我有一个自定义查找器,它可以为当前用户获取某个项目的通知。通知按消息分组,例如“new_comment”。通过查询,我的结果中有消息,message_count
有没有办法在查找器中以 key => value 格式转换此查询,以便我可以将其放入 message => message_format
//finder code;
return $query->contain([
'Notifications' => function ($q)use($userId) {
$q->select(['item_id','message','message_count'=> 'COUNT(message)']);
$q->where(['Notifications.user_id' => $userId]);
$q->group(['Notifications.message']);
return $q;
}
]);
最佳答案
使用Cake\Collection\Collection
的combine
方法
关于mysql - 将计数查询转换为 CakePHP 中包含语句中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39161957/