Skip to content

Commit

Permalink
Adding test to prove that matching() and contain() work for the same
Browse files Browse the repository at this point in the history
association path
  • Loading branch information
lorenzo committed Dec 18, 2014
1 parent d7a48f7 commit 63546f7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -2285,4 +2285,27 @@ public function testMatchingWithContain() {
$this->assertEquals(2, $result->_matchingData['tags']->id);
}

/**
* Tests that it is possible to call matching and contain on the same
* association with only onle level of depth.
*
* @return void
*/
public function testNotSoFarMatchingWithContainOnTheSameAssociation() {
$table = TableRegistry::get('articles');
$table->belongsToMany('tags');

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

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

}

0 comments on commit 63546f7

Please sign in to comment.