Skip to content
Permalink
Browse files

Allow any contain call to overwrite the eagerloader.

The override parameter should always work when used.

Refs #7412
  • Loading branch information...
markstory committed Sep 20, 2015
1 parent 06c7f1e commit b4171932551ad95afe2987efee11644e2d52dc17
Showing with 23 additions and 1 deletion.
  1. +1 −1 src/ORM/Query.php
  2. +22 −0 tests/TestCase/ORM/QueryTest.php
@@ -287,7 +287,7 @@ public function eagerLoader(EagerLoader $instance = null)
*/
public function contain($associations = null, $override = false)
{
if (empty($associations) && $override) {
if ($override) {
$this->_eagerLoader = null;
}
@@ -1822,6 +1822,28 @@ public function testCacheIntegrationWithFormatResults()
$this->assertSame($expected, $results);
}
/**
* Test overwriting the contained associations.
*
* @return void
*/
public function testContainOverwrite()
{
$table = TableRegistry::get('Articles');
$table->hasMany('Comments');
$table->belongsTo('Authors');
$query = $table->find();
$query->contain(['Comments']);
$this->assertEquals(['Comments'], array_keys($query->contain()));
$query->contain(['Authors'], true);
$this->assertEquals(['Authors'], array_keys($query->contain()));
$query->contain(['Comments', 'Authors'], true);
$this->assertEquals(['Comments', 'Authors'], array_keys($query->contain()));
}
/**
* Integration test to show filtering associations using contain and a closure
*

0 comments on commit b417193

Please sign in to comment.
You can’t perform that action at this time.