diff --git a/lib/Doctrine/Relation/Association.php b/lib/Doctrine/Relation/Association.php index 4cc1760c4..d2e46a5c8 100644 --- a/lib/Doctrine/Relation/Association.php +++ b/lib/Doctrine/Relation/Association.php @@ -57,16 +57,11 @@ class Doctrine_Relation_Association extends Doctrine_Relation $component = $this->definition['refTable']->getComponentName(); switch ($context) { case "record": - $sub = 'SQL:SELECT ' . $this->definition['foreign']. - ' FROM ' . $this->definition['refTable']->getTableName(). - ' WHERE ' . $this->definition['local'] . - ' IN (' . substr(str_repeat("?, ", $count),0,-2) . - ')'; - + $sub = substr(str_repeat("?, ", $count),0,-2); $dql = 'FROM ' . $this->getTable()->getComponentName(); $dql .= '.' . $component; $dql .= ' WHERE ' . $this->getTable()->getComponentName() - . '.' . $this->getTable()->getIdentifier() . ' IN (' . $sub . ')'; + . '.' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')'; break; case "collection": $sub = substr(str_repeat("?, ", $count),0,-2); @@ -93,6 +88,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation } else { $coll = Doctrine_Query::create()->parseQuery($this->getRelationDql(1))->execute(array($id)); } + $coll->setReference($record, $this); return $coll; } } diff --git a/tests/classes.php b/tests/classes.php index 779172461..e7ba15f17 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -67,8 +67,8 @@ class Address extends Doctrine_Record { public function setUp() { - $this->hasMany('User', array('local' => 'user_id', - 'foreign' => 'address_id', + $this->hasMany('User', array('local' => 'address_id', + 'foreign' => 'user_id', 'refClass' => 'EntityAddress')); } public function setTableDefinition() {