Skip to content
Permalink
Browse files

Only reset contain options, don't clear matching() state.

Refs #7412
  • Loading branch information...
markstory committed Sep 30, 2015
1 parent b417193 commit 5ec0a0ca9644460ba12b5c4e09451cfdd0dffdb0
Showing with 45 additions and 1 deletion.
  1. +15 −0 src/ORM/EagerLoader.php
  2. +1 −1 src/ORM/Query.php
  3. +29 −0 tests/TestCase/ORM/EagerLoaderTest.php
@@ -141,6 +141,21 @@ public function contain($associations = [])
return $this->_containments = $associations;
}
/**
* Remove any existing non-matching based containments.
*
* This will reset/clear out any contained associations that were not
* added via matching().
*
* @return void
*/
public function clearContain()
{
$this->_containments = [];
$this->_normalized = $this->_loadExternal = null;
$this->_aliasList = [];
}
/**
* Set whether or not contained associations will load fields automatically.
*
@@ -288,7 +288,7 @@ public function eagerLoader(EagerLoader $instance = null)
public function contain($associations = null, $override = false)
{
if ($override) {
$this->_eagerLoader = null;
$this->_eagerLoader->clearContain();
}
$result = $this->eagerLoader()->contain($associations);
@@ -443,6 +443,35 @@ public function testNormalizedPath()
);
}
/**
* Test clearing containments but not matching joins.
*
* @return void
*/
public function testClearContain()
{
$contains = [
'clients' => [
'orders' => [
'orderTypes',
'stuff' => ['stuffTypes']
],
'companies' => [
'categories'
]
]
];
$loader = new EagerLoader();
$loader->contain($contains);
$loader->matching('clients.addresses');
$this->assertNull($loader->clearContain());
$result = $loader->normalized($this->table);
$this->assertEquals([], $result);
$this->assertArrayHasKey('clients', $loader->matching());
}
/**
* Helper function sued to quoted both keys and values in an array in case
* the test suite is running with auto quoting enabled

0 comments on commit 5ec0a0c

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