diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 83639f14424..ec9658476cf 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1320,7 +1320,7 @@ public function queryAssociation(Model $Model, &$LinkModel, $type, $association, } } - $selfJoin = ($LinkModel->name === $Model->name); + $selfJoin = ($Model->name === $LinkModel->name); if (!empty($fetch) && is_array($fetch)) { if ($recursive > 0) { @@ -1605,14 +1605,14 @@ public function generateAssociationQuery(Model $Model, $linkModel, $type, $assoc switch ($type) { case 'hasOne': case 'belongsTo': - $self = ($Model->name === $linkModel->name); - $conditions = $this->_mergeConditions( $assocData['conditions'], - $this->getConstraint($type, $Model, $linkModel, $association, array_merge($assocData, compact('external', 'self'))) + $this->getConstraint($type, $Model, $linkModel, $association, array_merge($assocData, compact('external'))) ); - if (!$self && $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) { @@ -1733,7 +1733,7 @@ public function generateAssociationQuery(Model $Model, $linkModel, $type, $assoc * @return array Conditions array defining the constraint between $model and $association */ public function getConstraint($type, $model, $linkModel, $alias, $assoc, $alias2 = null) { - $assoc += array('external' => false, 'self' => false); + $assoc += array('external' => false); if (empty($assoc['foreignKey'])) { return array();