Skip to content

Commit

Permalink
Making sure contain and matching clashes are always resolved, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 14, 2015
1 parent 63a7531 commit 9969273
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ORM/EagerLoader.php
Expand Up @@ -465,10 +465,15 @@ protected function _resolveJoins($associations, $matching = [])
$options->associations(),
$inMatching ? $mathching[$table] : []
);
} else {
$options->canBeJoined(false);
$this->_loadExternal[] = $options;
continue;
}

if ($inMatching) {
$this->_correctStrategy($options, $table);
}

$options->canBeJoined(false);
$this->_loadExternal[] = $options;
}
return $result;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -670,4 +670,30 @@ public function testFindMatchingOverwrite()
$this->assertNotNull($result->article);
$this->assertEquals($result->article, $result->_matchingData['Articles']);
}

/**
* Tests that matching does not overwrite associations in contain
*
* @see https://github.com/cakephp/cakephp/issues/5584
* @return void
*/
public function testFindMatchingOverwrite2()
{
$comments = TableRegistry::get('Comments');
$comments->belongsTo('Articles');

$articles = TableRegistry::get('Articles');
$articles->belongsTo('Authors');
$articles->belongsToMany('Tags');

$result = $comments
->find()
->matching('Articles.Tags', function($q) {
return $q->where(['Tags.id' => 2]);
})
->contain('Articles.Authors')
->first();

$this->assertNotNull($result->article->author);
}
}

0 comments on commit 9969273

Please sign in to comment.