1
我Price
屬於關聯Season
匹配協會和沒有相關的記錄CakePHP的3
我想查詢的季節過去了,以及任何有沒有匹配特定日期範圍內,所有價格的關聯(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?