This function will add entries in the contain graph.
### Example:
Bring only articles that were tagged with 'cake'
$query->matching('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 were commented by 'markstory'
$query->matching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
As this function will create INNER 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 user commenting more than once in the same article.
### Example:
Bring unique articles that were commented by 'markstory'
$query->distinct(['Articles.id'])
->matching('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.