From b7527c6c3b365242e591fc03dbe4e925cca40cf8 Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Wed, 27 Nov 2013 20:30:06 -0300 Subject: [PATCH] Test for a self join only when needed. --- lib/Cake/Model/Datasource/DboSource.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 7578bf67d..415f4a061 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1599,18 +1599,17 @@ class DboSource extends DataSource { $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),