Based on your current database design, the easiest thing would be to
have a separate inbox/outbox:

class Message extends AppModel {
  var $belongsTo = array(
    'Sender' => array('className' => 'User'),
    'Receiver' => array('className' => 'User')
  );
}

class User extends AppModel {
  var $hasMany = array(
    'SentMessage' => array('className' => 'Message', 'foreignKey' =>
'sender_id'),
    'ReceivedMessage' => array('className' => 'Message', 'foreignKey'
=> 'receiver_id')
  );
}

If you need to fetch all sent and received for a user at the same
time, you'd do it manually

$messages = $this->Message->find('all', array(
  'conditions' => array(
    'or' => array(
      'Message.sender_id' => $userId,
      'Message.receiver_id' => $userId,
    )
  )
));

For different database designs there are other solutions, it all
depends on what you want to achiveve.

hth
grigri



On Dec 16, 3:56 am, Jnic <[email protected]> wrote:
> nobody ?
>
> On Dec 14, 6:57 pm, Adriano Varoli Piazza <[email protected]> wrote:
>
> > On 14 dic, 19:52, Jnic <[email protected]> wrote:
>
> > > Hi,
>
> > > I'm doing a private message system for my website. I've created a
> > > database called messages, which contains :
>
> > > id,sender_id,reciever_id,subject,message,date
>
> > Unrelated, but do note that 'reciever' is a typo: correct spelling is
> > 'receiver'. Spelling might bite you using Cake, as most of the
> > automagic relies on correct name relationships.
>
> > --
> > Saludos
> > Adriano
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to