Skip to content

Commit

Permalink
Test for a self join only when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
bar committed Dec 10, 2013
1 parent a2f043d commit b7527c6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1599,18 +1599,17 @@ public function generateAssociationQuery(Model $Model, Model $LinkModel, $type,
$this->getConstraint($type, $Model, $LinkModel, $association, array_merge($assocData, compact('external')))
);

$selfJoin = ($Model->name === $LinkModel->name);

if ($external && !$selfJoin) {
$modelAlias = $Model->alias;
foreach ($conditions as $key => $condition) {
if (is_numeric($key) && strpos($condition, $modelAlias . '.') !== false) {
unset($conditions[$key]);
if ($external) {
// Self join
if ($Model->name !== $LinkModel->name) {
$modelAlias = $Model->alias;
foreach ($conditions as $key => $condition) {
if (is_numeric($key) && strpos($condition, $modelAlias . '.') !== false) {
unset($conditions[$key]);
}
}
}
}

if ($external) {
$query = array_merge($assocData, array(
'conditions' => $conditions,
'table' => $this->fullTableName($LinkModel),
Expand Down

0 comments on commit b7527c6

Please sign in to comment.