我有一个属于的Price
关联Season
我正在尝试查询在季节中通过时与特定日期范围匹配的所有价格以及任何没有的价格(Prices.season_id=0
)
这是我所拥有的:
// build the query
$query = $this->Prices->find()
->where(['product_id'=>$q['product_id']])
->contain(['Seasons']);
if(!empty($to_date) && !empty($from_date)) {
$query->matching('Seasons', function ($q) {
return $q->where([
'from_date <= ' => $to_date,
'to_date >= ' => $from_date
]);
});
}
但是,这只会返回与季节明确关联的价格。我如何让它也返回 Price.season_id=0 ?