Skip to content

Commit

Permalink
Added test for matching with dot notation
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 5, 2014
1 parent 3f47f6d commit 17a5c85
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Cake/Test/TestCase/ORM/QueryTest.php
Expand Up @@ -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()
*
Expand Down

0 comments on commit 17a5c85

Please sign in to comment.