我有一个检索到的餐厅清单。当餐厅菜单为空时,该餐厅以最后顺序显示。.我该怎么办..你能帮忙吗?
我的查询是:
$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();
答案 0 :(得分:0)
简单的解决方案:
通过实现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”,然后选择1,否则0
根据结果排序