Skip to content

Commit

Permalink
Adding test to prove that using contain and matchin on the same assoc…
Browse files Browse the repository at this point in the history
… works
  • Loading branch information
lorenzo committed Dec 13, 2014
1 parent 5571df7 commit 6f8c3bd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -2280,4 +2280,29 @@ public function testContainWithStrategyOverride() {
$this->assertNull($articles[2]->author);
}

/**
* Tests that it is possible to call matching and contain on the same
* association.
*
* @return void
*/
public function testMatchingWithContain() {
$query = new Query($this->connection, $this->table);
$table = TableRegistry::get('authors');
$table->hasMany('articles');
TableRegistry::get('articles')->belongsToMany('tags');

$result = $query->repository($table)
->select()
->matching('articles.tags', function ($q) {
return $q->where(['tags.id' => 2]);
})
->contain('articles')
->first();

$this->assertEquals(1, $result->id);
$this->assertCount(2, $result->articles);
$this->assertEquals(2, $result->_matchingData['tags']->id);
}

}

0 comments on commit 6f8c3bd

Please sign in to comment.