Permalink
Browse files

Test for a self join only when needed.

  • Loading branch information...
1 parent a2f043d commit b7527c6c3b365242e591fc03dbe4e925cca40cf8 @bar bar committed Nov 27, 2013
Showing with 8 additions and 9 deletions.
  1. +8 −9 lib/Cake/Model/Datasource/DboSource.php
@@ -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),

0 comments on commit b7527c6

Please sign in to comment.