diff --git a/manual/codes/Basic Components - Collection - Key mapping.php b/manual/codes/Basic Components - Collection - Key mapping.php new file mode 100644 index 000000000..c2081f544 --- /dev/null +++ b/manual/codes/Basic Components - Collection - Key mapping.php @@ -0,0 +1,31 @@ +setAttribute(Doctrine::ATTR_COLL_KEY, 'id'); + +// now user collections will use the values of +// id column as element indexes + +$users = $user->getTable()->findAll(); + +foreach($users as $id => $user) { + print $id . $user->name; +} + +// mapping name column + +$user = new User(); + +$user->setAttribute(Doctrine::ATTR_COLL_KEY, 'name'); + +// now user collections will use the values of +// name column as element indexes + +$users = $user->getTable()->findAll(); + +foreach($users as $name => $user) { + print $name . $user->type; +} +?> diff --git a/manual/docs/Basic Components - Collection - Key mapping.php b/manual/docs/Basic Components - Collection - Key mapping.php new file mode 100644 index 000000000..a8b9cf891 --- /dev/null +++ b/manual/docs/Basic Components - Collection - Key mapping.php @@ -0,0 +1,3 @@ +Sometimes you may not want to use normal indexing for collection elements. For example in +some cases mapping primary keys as collection keys might be useful. The following example +demonstrates how this can be achieved. diff --git a/manual/documentation.php b/manual/documentation.php index eebdd8c22..df8eac1f1 100644 --- a/manual/documentation.php +++ b/manual/documentation.php @@ -138,6 +138,7 @@ $menu = array("Getting started" => "Saving the collection", "Deleting collection", //"Fetching strategies", + "Key mapping", "Loading related records", "Collection expanding", ), @@ -366,12 +367,12 @@ $menu = array("Getting started" => if( ! file_exists("docs/$title - $k - $v2.php")) { $missing[0]++; $str .= " [ doc ] "; - //touch("docs/$title - $k - $v2.php"); + touch("docs/$title - $k - $v2.php"); } if( ! file_exists("codes/$title - $k - $v2.php")) { $missing[1]++; $str .= " [ code ] "; - //touch("codes/$title - $k - $v2.php"); + touch("codes/$title - $k - $v2.php"); } @@ -448,27 +449,28 @@ $menu = array("Getting started" => if(isset($ex[1])) { $name = implode(" - ", $stack); - print "".$paths[$curr]."
"; + print "".$paths[$curr]."
"; $n = $numbers; $o = $paths[$n[0]]; - $s = implode(".", array($n[0], $n[1])); - $o2 = $paths[$s]; + $numpath = implode(".", array($n[0], $n[1])); + $o2 = $paths[$numpath]; $value = $menu[$o]; - if( ! is_array($value)) + if( ! is_array($value)) exit; - + if(in_array($o2, $value)) { render_block($name); - } else { + } else { $value = $menu[$o][$o2]; if(is_array($value)) { foreach($value as $k => $title) { - print "
".$title."
"; + $numpath2 = $numpath . '.' . ($k + 1); + print "
".$title."
"; $s = $name." - ".$title;