loadRelated() now works for many-to-many associations
This commit is contained in:
parent
7ef7031c37
commit
d6eb961c0c
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user