From 6c0b5fd36cd234c11fe8cf10e19057ae4af5d824 Mon Sep 17 00:00:00 2001 From: nightfreak Date: Sat, 11 Aug 2007 18:24:19 +0000 Subject: [PATCH] added the fix for ticket #398. also fixed the missing $coll->setReference() in Doctrine_Relation_Association::fetchRelatedFor() --- lib/Doctrine/Relation/Association.php | 10 +++------- tests/classes.php | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) 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() {