我有一个检索到的餐馆名单 . 当餐厅菜单是空的,餐厅显示在最后的订单..我做什么..你能帮助..
我的查询是:
$restaurantList = $this->Restaurants->find('all', [
'conditions' => $conditions,
'contain' => [
'DeliveryLocations' => [
'conditions' => $areaLocationConditions,
],
'RestaurantMenus' => [
'conditions' => [
'RestaurantMenus.status' => 1,
'RestaurantMenus.delete_status' => 'N'
]
]
],
'limit' => 5,
'order' => 'Restaurants.id DESC'
])->hydrate(false)->toArray();
1 回答
简单解决方案
通过实现CounterCache https://book.cakephp.org/3.0/en/orm/behaviors/counter-cache.html并按缓存结果排序 .
更复杂:
通过使用Case语句
https://book.cakephp.org/3.0/en/orm/query-builder.html#case-statements
如果餐厅有菜单,则选择'has_menus',然后选择其他0
按此结果排序