Skip to content

Commit 6f8c3bd

Browse files
committed
Adding test to prove that using contain and matchin on the same assoc works
1 parent 5571df7 commit 6f8c3bd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/TestCase/ORM/QueryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,4 +2280,29 @@ public function testContainWithStrategyOverride() {
22802280
$this->assertNull($articles[2]->author);
22812281
}
22822282

2283+
/**
2284+
* Tests that it is possible to call matching and contain on the same
2285+
* association.
2286+
*
2287+
* @return void
2288+
*/
2289+
public function testMatchingWithContain() {
2290+
$query = new Query($this->connection, $this->table);
2291+
$table = TableRegistry::get('authors');
2292+
$table->hasMany('articles');
2293+
TableRegistry::get('articles')->belongsToMany('tags');
2294+
2295+
$result = $query->repository($table)
2296+
->select()
2297+
->matching('articles.tags', function ($q) {
2298+
return $q->where(['tags.id' => 2]);
2299+
})
2300+
->contain('articles')
2301+
->first();
2302+
2303+
$this->assertEquals(1, $result->id);
2304+
$this->assertCount(2, $result->articles);
2305+
$this->assertEquals(2, $result->_matchingData['tags']->id);
2306+
}
2307+
22832308
}

0 commit comments

Comments
 (0)