Thursday, October 18, 2012

Re: Cakephp find order by then group by

The group by is throwing it off.  When you use a group and an order together you typically do not get the expected result. In order to get the desired results you might need to do an inner select.  I don't remember the correct way to do it off the top of my head though to get what you are looking for.  I do know though that the group by clause is what is causing your issues.

On Thu, Oct 18, 2012 at 4:47 AM, anwar korti <anwarkorti@gmail.com> wrote:

Hello In a Message controller I try to display the latest message of each user (sender) for a connected one (receiver)  I try this but I still find the first entry. Thank you for your help

Messages table:

  • id
  • user_id -> Sender
  • receiver_id -> receiver
  • content 
  • created -> datetime
  • statut -> read or not

    $this->set('messages', $this->Message->find('all',
array
(
'conditions' => array('Message.receiver_id'=>$user),
'order' => array('Message.created desc'),
'group'=>'Message.user_id')));

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: