I execute the following request:
$agPoi = $this->Agpois->get($agPoiId, [
'contain' => [
'Agpoititles.Agthemelanguages' => function ($q) use ($languageId) {
return $q->where([
'language_id' => $languageId,
]);
}
]
]);
Surprisingly, it returns me all agpoititles
with only one containing a not empty aghtemelanguage
object for which 'language_id' => $languageId
.
But I'm not interested by agpoititles
not containing an agthemelanguage
object.
How to modify the request to only the ones I want?
EDIT
Agpois hasMany
Agpoititles
AgpoiTitles belongsTo
Agthemelanguages
Agthemelanguages hasOne
Agpoititles
SO I expect to get agPoi with THE Agpoititles
for which its agthemelanguage->language_id
= $languageId
Edit 2
So I tried to use matching() and it works if you pay attention to look for the result in _matchingData
as it's explained in the doc ;).
$agPoi = $this->Agpois->find()
->contain(['Agpoititles.Agthemelanguages'])
->matching('Agpoititles.Agthemelanguages', function ($q) use ($languageId, $poiId) {
return $q->where([
'Agpois.id' => $poiId,
'language_id' => $languageId
]);
}
)
->first();