Skip to content

Commit

Permalink
Adding a test for notMatching and deep associations
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 6, 2015
1 parent cd4cc09 commit b76e7b6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -2905,4 +2905,30 @@ public function testNotMatchingBelongsToMany()
];
$this->assertEquals($expected, $results);
}

public function testNotMatchingDeep()
{
$table = TableRegistry::get('authors');
$articles = $table->hasMany('articles');
$articles->belongsToMany('tags');

$results = $table->find()
->hydrate(false)
->notMatching('articles.tags', function ($q) {
return $q->where(['tags.name' => 'tag3']);
})
->distinct(['authors.id']);

$this->assertEquals([1, 2, 4], $results->extract('id')->toList());

$results = $table->find()
->hydrate(false)
->notMatching('articles.tags', function ($q) {
return $q->where(['tags.name' => 'tag3']);
})
->matching('articles')
->distinct(['authors.id']);

$this->assertEquals([1], $results->extract('id')->toList());
}
}

0 comments on commit b76e7b6

Please sign in to comment.