diff --git a/README.md b/README.md index d3ea327..87e6bdb 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,8 @@ The above example will issue 1 query to the database to fetch all `YourModel` in This is where the two new hydrator modes come into play. Rewriting the above example using these new modes we get this. - Doctrine_Manager::getInstance()->registerHydrator('ArrayCoupled', 'Doctrine_Hydrator_ArrayCoupled'); - Doctrine_Manager::getInstance()->registerHydrator('RecordCoupled', 'Doctrine_Hydrator_RecordCoupled'); + Doctrine_Manager::getInstance()->registerHydrator('ArrayCoupled', 'Doctrine_Hydrator_ArrayCoupled_Driver'); + Doctrine_Manager::getInstance()->registerHydrator('RecordCoupled', 'Doctrine_Hydrator_RecordCoupled_Driver'); $yourModels = Doctrine_Core::getTable('YourModel')->findAll('RecordCoupled'); foreach($yourModels as $yourModel) diff --git a/lib/Doctrine/Template/Listener/LooselyCoupled.php b/lib/Doctrine/Template/Listener/LooselyCoupled.php index cdcfcba..30a8d9f 100644 --- a/lib/Doctrine/Template/Listener/LooselyCoupled.php +++ b/lib/Doctrine/Template/Listener/LooselyCoupled.php @@ -53,25 +53,12 @@ public function preDqlSelect(Doctrine_Event $event) $query = $event->getQuery(); $relations = array_keys($this->_options); - + $components = $this->_getDqlCallbackComponents($query); - $rootComponentName = false; foreach ($components as $alias => $component) { - if(!$rootComponentName) - { - $rootComponentName = $component['table']->getComponentName(); - } - if (isset($component['relation'])) - { - foreach ($event->getInvoker()->getTable()->getRelations() as $relation) - { - if ($component['table'] == $relation->getTable() && $relation->getTable()->hasTemplate('LooselyCoupleable')) - { - $query->addPendingJoinCondition($alias, $alias.'.obj_type = "'.$rootComponentName.'"'); - continue; - } - } + if (isset($component['relation']) && $event->getInvoker()->getTable()->getComponentName() == $component['relation']['localTable']->getComponentName() && $component['table']->hasTemplate('LooselyCoupleable')) { + $query->addPendingJoinCondition($alias, $alias.'.obj_type = "'.$component['relation']['localTable']->getComponentName().'"'); } } } @@ -86,7 +73,7 @@ protected function _getDqlCallbackComponents($query) } $copy = $query->copy(); - $copy->getSqlQuery($params); + $copy->getSqlQuery($params, 0); $componentsAfter = $copy->getQueryComponents(); if ($componentsBefore !== $componentsAfter)