I have three tables in the postgres
.
ChatMessages
ChatReactions
ChatReactionTypes
The association looks like this :
I am trying to get the user reaction list message wise. Like this example. This modal is opened per message wise :
I have tried the following query in CakePHP query builder :
$this->ChatMessages->find()
->contain([
'ChatReactions.ChatReactionTypes',
])
->contain('ChatReactions', function($q) {
$q->select([
'chat_message_id',
'chat_reaction_type_id',
'count' => $q->func()->count('chat_reaction_type_id')
])
->innerJoinWith('ChatReactionTypes')
->group(['chat_reaction_type_id', 'chat_message_id']);
return $q;
})
->order([
'ChatMessages.created' => 'ASC',
])
->all()
;
This is the result :
The chat_reactions
(marked red in the image above) object is grouped by reaction_type_id. I want to have all the users
associated with that id inside chat_reactions
.