mysql - 将计数查询转换为 CakePHP 中包含语句中的列表

标签 mysql cakephp orm cakephp-3.0

我有一个自定义查找器,它可以为当前用户获取某个项目的通知。通知按消息分组,例如“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\Collectioncombine方法

关于mysql - 将计数查询转换为 CakePHP 中包含语句中的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39161957/

相关文章:

php - 子类别 MySql 和 php

php - 在数据库users表中保存users 70权限可以吗?

java - 如何在hibernate中使用条件转换mysql连接查询

cakephp - 易于使用/学习 PHP 框架?

CakePHP - 包含应用程序目录之外的目录中的类

c# - 这个ORM有什么问题吗?

PHPMailer 意外启动垃圾邮件

cakephp - Cakephp 中的编码斜线中断路由

node.js - 使用 Prisma 进行深度嵌套事务写入

web-services - NHibernate 投影到 DTO