Commit 90bd728d authored by zYne's avatar zYne

Support for collection key mapping

parent da9d179d
<?php
// mapping id column
$user = new User();
$user->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;
}
?>
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.
......@@ -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 .= " [ <font color='red'>doc</font> ] ";
//touch("docs/$title - $k - $v2.php");
touch("docs/$title - $k - $v2.php");
}
if( ! file_exists("codes/$title - $k - $v2.php")) {
$missing[1]++;
$str .= " [ <font color='red'>code</font> ] ";
//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 "<b class='title'>".$paths[$curr]."</b><hr>";
print "<a name='$path'><b class='title'>".$paths[$curr]."</b></a><hr>";
$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 "<br \><b class='title'>".$title."</b><hr style='height: 1px' \>";
$numpath2 = $numpath . '.' . ($k + 1);
print "<br \><a name='".$numpath2."'><b class='title'>".$title."</b></a><hr style='height: 1px' \>";
$s = $name." - ".$title;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment