Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 4 additions & 17 deletions lib/Doctrine/Template/Listener/LooselyCoupled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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().'"');
}
}
}
Expand All @@ -86,7 +73,7 @@ protected function _getDqlCallbackComponents($query)
}

$copy = $query->copy();
$copy->getSqlQuery($params);
$copy->getSqlQuery($params, 0);
$componentsAfter = $copy->getQueryComponents();

if ($componentsBefore !== $componentsAfter)
Expand Down