1

I am running this query

 return $this->find('all', array(
                'conditions' => array(
                    'OR' => array(
                        'Chat.sender_id' => $user_id,
                        'Chat.receiver_id' => $user_id
                    )

                ),


                'group' => array('converstation_id'),
                 'order' => array('Chat.id DESC')


            ));

But If I add Group By then order don't work in this query. What I am doing wrong?

hellosheikh
  • 2,929
  • 8
  • 49
  • 115
  • 1
    They can't work together at least from single query. You need to use sub query or multiple query, See here http://stackoverflow.com/questions/10030787/using-order-by-and-group-by-together – Manohar Khadka Mar 08 '17 at 09:27
  • Order can only be applied after Group. This means the ordering is being applied to the grouped results. – GordonM Mar 08 '17 at 09:50

1 Answers1

-1

The order should be as followes:

'order' = array('Chat.id' => 'DESC')

This, as order requests an array where the value is the order direction. More information on https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html

Paul
  • 79
  • 1
  • 7