diff --git a/Doctrine/Association.php b/Doctrine/Association.php index beb585943..f2728dc8e 100644 --- a/Doctrine/Association.php +++ b/Doctrine/Association.php @@ -45,13 +45,16 @@ class Doctrine_Association extends Doctrine_Relation { " WHERE ".$this->local. " IN (".substr(str_repeat("?, ", $count),0,-2).")"; - $dql = "FROM ".$this->table->getComponentName(); - - if($context != 'record') - $dql .= ":".$this->associationTable->getComponentName(); - - $dql .= " WHERE ".$this->table->getComponentName().".".$this->table->getIdentifier(). - " IN ($sub)"; + switch($context): + case "record": + $dql = "FROM ".$this->table->getComponentName(); + $dql .= ":".$this->associationTable->getComponentName(); + $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; } diff --git a/Doctrine/Collection.php b/Doctrine/Collection.php index 41810cfcc..a3edf8520 100644 --- a/Doctrine/Collection.php +++ b/Doctrine/Collection.php @@ -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); - $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); + } } }