In a project I'm working on, I have a messages table as well.  In the
message.php I have the following association

var $belongsTo = array(
     'Recipient' =>
         array('className' => 'User',
                 'foreignKey' => 'recipient_id',
          ),

     'Sender' =>
          array('className' => 'User',
                 'foreignKey' => 'sender_id',
         ),
);

The className is User for both, but the instances of the class have
unique names, ie Recipient and Sender.

Now if you want to get all the messages sent by user id 2:

$sentBy2 = $this->Message->findAll(array('Sender.id' => 2));  //didn't
test this

Hope that helps,
Russell

On Apr 9, 8:41 am, "erdbeerelse" <[EMAIL PROTECTED]> wrote:
> hello,
>
> I have a question about naming convention with foreign keys. in my
> first table (users) I have a primary key id, which is the user id
> followed by username, useradress.... in my second table (msgs) I save
> messages from a user to a user. So I want to reference the foreigns
> keys fromuser and touser to the table users and the field id.
>
> the conventions say, that the foreign key in my table msgs should be
> user_id (=table_fieldname). My problem is, that I need this foreign
> key twice just like:
>
> from_user_id and to_user_id
>
> Could anyboldy please help me to figure it out? Thanks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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