Skip to content
Permalink
Browse files

Asserting that tuple comparison is used for eager laoding HasMany

  • Loading branch information...
lorenzo committed Jan 12, 2014
1 parent f0ba802 commit f664429fa0d3180329ddda4ac012d9ba4504835b
Showing with 9 additions and 1 deletion.
  1. +9 −1 Test/TestCase/ORM/Association/HasManyTest.php
@@ -18,6 +18,7 @@
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Expression\QueryExpression;
use Cake\Database\Expression\TupleComparison;
use Cake\ORM\Association\HasMany;
use Cake\ORM\Entity;
use Cake\ORM\Query;
@@ -430,7 +431,7 @@ public function testEagerLoaderMultipleKeys() {
$this->author->primaryKey(['id', 'site_id']);
$association = new HasMany('Articles', $config);
$keys = [[1, 10], [2, 20], [3, 30], [4, 40]];
$query = $this->getMock('Cake\ORM\Query', ['all'], [null, null]);
$query = $this->getMock('Cake\ORM\Query', ['all', 'andWhere'], [null, null]);
$this->article->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
$results = [
@@ -440,6 +441,13 @@ public function testEagerLoaderMultipleKeys() {
$query->expects($this->once())->method('all')
->will($this->returnValue($results));
$tuple = new TupleComparison(
['Articles.author_id', 'Articles.site_id'], $keys, [], 'IN'
);
$query->expects($this->once())->method('andWhere')
->with($tuple)
->will($this->returnSelf());
$callable = $association->eagerLoader(compact('keys', 'query'));
$row = ['Authors__id' => 2, 'Authors__site_id' => 10, 'username' => 'author 1'];
$result = $callable($row);

0 comments on commit f664429

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