【发布时间】:2017-08-24 10:49:57
【问题描述】:
只有当二级关联数据遵守给定条件时,我才想获得关联。
查询可能会更好地解释我尝试做的事情。
$selSite = $this->Sites->get($selSiteId, [
'contain' => [
'Agplans.Products' => function ($q) {
return $q
->where([
'Products.type' => 'hosting',
]);
}
]
]);
所以我只希望 agplan 的关联产品符合条件。
但结果是:
'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,
...,
},
...,
}
],
我的问题是用product => null 获取agplan[0]。
这不是我从doc 所理解的。
如何仅使用'product' => object(App\Model\Entity\Product) 获取agplan?
【问题讨论】:
-
对我来说听起来像 stackoverflow.com/questions/26799094/…。
-
@ndm 我不认为这是同一个问题。在这里,我不想得到几个关联匹配条件的站点,我只
get一个特定站点。我只是想在这里过滤掉它的关联。 doc 解释了什么告诉It is also possible to restrict **deeply-nested associations** using the dot notation:。我没有看到我在这里不明白的地方。
标签: cakephp associations filtering query-builder cakephp-3.x