diff --git a/Cake/Test/TestCase/ORM/QueryTest.php b/Cake/Test/TestCase/ORM/QueryTest.php index 7bf250d1d1c..62ee6344c93 100644 --- a/Cake/Test/TestCase/ORM/QueryTest.php +++ b/Cake/Test/TestCase/ORM/QueryTest.php @@ -917,6 +917,45 @@ public function testFilteringByBelongsToManyNoHydration() { $this->assertEquals($expected, $results); } +/** + * Tests that it is possible to filter by deep associations + * + * @return void + */ + public function testMatchingDotNotation() { + $query = new Query($this->connection, $this->table); + $table = TableRegistry::get('authors'); + TableRegistry::get('articles'); + $table->hasMany('articles'); + TableRegistry::get('articles')->belongsToMany('tags'); + + $results = $query->repository($table) + ->select() + ->hydrate(false) + ->matching('articles.tags', function($q) { + return $q->where(['tags.id' => 2]); + }) + ->toArray(); + $expected = [ + [ + 'id' => 1, + 'name' => 'mariano', + 'articles' => [ + 'id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'author_id' => 1, + 'published' => 'Y', + 'tags' => [ + 'id' => 2, + 'name' => 'tag2' + ] + ] + ] + ]; + $this->assertEquals($expected, $results); + } + /** * Test setResult() *