Permalink
Browse files

Merge pull request #10868 from cakephp/issue-10813

Reset eager loaders before triggering before find.
  • Loading branch information...
lorenzo committed Jul 6, 2017
2 parents 02c51aa + 2d59a95 commit 82afbb005f6a2b42f3e370122fb69ea51a64f493
Showing with 29 additions and 1 deletion.
  1. +1 −1 src/ORM/Query.php
  2. +28 −0 tests/TestCase/ORM/QueryRegressionTest.php
View
@@ -756,6 +756,7 @@ public function applyOptions(array $options)
public function cleanCopy()
{
$clone = clone $this;
$clone->setEagerLoader(clone $this->getEagerLoader());
$clone->triggerBeforeFind();
$clone->enableAutoFields(false);
$clone->limit(null);
@@ -765,7 +766,6 @@ public function cleanCopy()
$clone->formatResults(null, true);
$clone->setSelectTypeMap(new TypeMap());
$clone->decorateResults(null, true);
$clone->setEagerLoader(clone $this->getEagerLoader());
return $clone;
}
@@ -741,6 +741,34 @@ public function testCountWithBind()
$this->assertEquals(1, $count);
}
/**
* Test count() with inner join containments.
*
* @return void
*/
public function testCountWithInnerJoinContain()
{
$this->loadFixtures('Articles', 'Authors');
$table = TableRegistry::get('Articles');
$table->belongsTo('Authors')->setJoinType('INNER');
$result = $table->save($table->newEntity([
'author_id' => null,
'title' => 'title',
'body' => 'body',
'published' => 'Y'
]));
$this->assertNotFalse($result);
$table->eventManager()
->on('Model.beforeFind', function (Event $event, $query) {
$query->contain(['Authors']);
});
$count = $table->find()->count();
$this->assertEquals(3, $count);
}
/**
* Tests that bind in subqueries works.
*

0 comments on commit 82afbb0

Please sign in to comment.