Conversation HM ConversationUser
I want to check if there is already a conversation with lets say user
1,2,4
The problem is that I need 'ConversationUser.user_id'=>$users in the
conditions somehow
but HAVING COUNT(*) = '.count($users) ALWAYS returns true then (we
already threw the wrong ones out.
Without the condition it will find other ones with the correct amount
of users too
So i am stuck here - how can i modify the query to get exactly the
conversations with user 1,2,4 (not 1,2,5 oder just 1,2 etc) if
existing?
thx!
/**
* checks if a conversation with exactly those users exist (not more,
not less0)
* //TODO: fixme
* @param array users to check on
* @param int limit
* needs at least 2 users
* @return array
*/
function existingConversations($users, $limit = 5) {
$options = array(
'conditions' =>
array('ConversationUser.user_id'=>$users,
'ConversationUser.status <'=>ConversationUser::STATUS_REMOVED),
'group' => array('ConversationUser.conversation_id
HAVING COUNT(*)
= '.count($users).''),
'contain' => array('Conversation'),
'fields' => array('Conversation.id',
'Conversation.title',
'Conversation.last_message'),
'limit' => $limit,
'order' => array('Conversation.last_message'=>'DESC')
);
return $this->ConversationUser->find('all', $options);
}
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en