I want to get associated only if the second level associated data respect the given condition.
The query will maybe better explain what I try to do.
$selSite = $this->Sites->get($selSiteId, [
'contain' => [
'Agplans.Products' => function ($q) {
return $q
->where([
'Products.type' => 'hosting',
]);
}
]
]);
So I expect an agplan
only if its associated product matches the condition.
But the result is:
'agplans' => [
(int) 0 => object(App\Model\Entity\Agplan) {
'id' => (int) 20,
'product_id' => (int) 4,
'product' => null,
...,
},
(int) 1 => object(App\Model\Entity\Agplan) {
'id' => (int) 21,
'site_id' => (int) 64,
'product_id' => (int) 75,
'product' => object(App\Model\Entity\Product) {
'id' => (int) 75,
...,
},
...,
}
],
My problem here is to get agplan[0]
with a product => null
.
It's not what I understood from the doc.
How to get the agplan
with 'product' => object(App\Model\Entity\Product)
only?