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

loadRelated() now works for many-to-many associations

This commit is contained in:
zYne 2006-09-08 22:02:38 +00:00
parent 7ef7031c37
commit d6eb961c0c
2 changed files with 15 additions and 14 deletions

View File

@ -45,13 +45,16 @@ class Doctrine_Association extends Doctrine_Relation {
" WHERE ".$this->local.
" IN (".substr(str_repeat("?, ", $count),0,-2).")";
switch($context):
case "record":
$dql = "FROM ".$this->table->getComponentName();
if($context != 'record')
$dql .= ":".$this->associationTable->getComponentName();
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier().
" IN ($sub)";
$dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier()." IN ($sub)";
break;
case "collection":
$dql = "FROM ".$this->associationTable->getComponentName().".".$this->table->getComponentName();
$dql .= " WHERE ".$this->associationTable->getComponentName().".".$this->local." IN ($sub)";
endswitch;
return $dql;
}

View File

@ -624,9 +624,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$list[] = $value;
endforeach;
}
$rel = $this->table->getRelation($name);
$dql = $rel->getRelationDql(count($list), 'collection');
$coll = $query->query($dql, $list);
$coll = $query->query($dql, $list);
$this->populateRelated($name, $coll);
}
/**
@ -677,16 +678,13 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
continue;
$sub = new Doctrine_Collection($table);
$association = $asf->getComponentName();
foreach($coll as $k => $related) {
if($related[$association][0]->get($local) == $record[$identifier]) {
$sub->add($related);
$coll->remove($k);
if($related->get($local) == $record[$identifier]) {
$sub->add($related->get($name));
}
}
$this->data[$key]->setRelated($name, $sub);
}
}
}