【发布时间】:2016-02-05 11:29:47
【问题描述】:
我有一个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
]);
});
}
但是,这只会返回与季节明确关联的价格。如何让它也返回 Prices.season_id=0?
【问题讨论】:
标签: orm associations matching cakephp-3.1