This function will add entries in the contain graph.
### Example:
Bring only articles that were not tagged with 'cake'
$query->notMatching('Tags', function ($q) {
return $q->where(['name' => 'cake']);
);
It is possible to filter by deep associations by using dot notation:
### Example:
Bring only articles that weren't commented by 'markstory'
$query->notMatching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
As this function will create a LEFT JOIN, you might want to consider
calling distinct on this query as you might get duplicate rows if
your conditions don't filter them already. This might be the case, for example,
of the same article having multiple comments.
### Example:
Bring unique articles that were commented by 'markstory'
$query->distinct(['Articles.id'])
->notMatching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
Please note that the query passed to the closure will only accept calling
select, where, andWhere and orWhere on it. If you wish to
add more complex clauses you can do it directly in the main query.
public notMatching ( string $assoc, callable $builder = null ) | ||
$assoc | string | The association to filter by |
$builder | callable | a function that will receive a pre-made query object that can be used to add custom conditions or selecting some fields |