1
0
mirror of synced 2024-12-13 06:46:03 +03:00

Support for collection key mapping

This commit is contained in:
zYne 2006-09-01 21:56:55 +00:00
parent da9d179d9f
commit 90bd728d81
3 changed files with 45 additions and 9 deletions

View File

@ -0,0 +1,31 @@
<?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;
}
?>

View File

@ -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.

View File

@ -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,13 +449,13 @@ $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))
@ -468,7 +469,8 @@ $menu = array("Getting started" =>
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;