I have following model associations:
//User Model
public $hasMany = array(
'MessageSent' => array(
'className' => 'Message',
'foreignKey' => 'sender_id'
),
'MessageReceived' => array(
'className' => 'Message',
'foreignKey' => 'receiver_id'
));
//Message Model
public $belongsTo = array(
'Sender' => array(
'className' => 'User',
'foreignKey' => 'sender_id'
),
'Receiver' => array(
'className' => 'User',
'foreignKey' => 'receiver_id'
)
);
Now i would like to fetch a User with the messages ordered by "created", so that i can create a message stream ala facebook.
$this->User->contain(array(
'MessageSent' => array('conditions' => array('MessageSent.receiver_id' =>
$this->Auth->user('id'))),
'MessageReceived' => array('conditions' => array('MessageReceived.sender_id' =>
$this->Auth->user('id')))
));
$partner = $this->User->find('all', array('conditions' => array('slug' =>
$this->request->params['slug'])));
So i need something like "ORDER BY Message.created" so that i get MessageSent and MessageReceived mixed together and ordered by date . How do i do that?