You give each association a different name, e.g:
var $belongsTo = array(
'User'=>array(
'className'=>'User',
'foreignKey'=>'user_id',
'fields'=>array('first_name', 'last_name')
),
'CreatedBy'=>array(
'className'=>'User',
'foreignKey'=>'created_by',
'fields'=>array('first_name', 'last_name')
),
'ModifiedBy'=>array(
'className'=>'User',
'foreignKey'=>'modified_by',
'fields'=>array('first_name', 'last_name')
)
);
Then, in your view you reference it as follows:
$xxx['CreatedBy']['first_name'].' '. $xxx['CreatedBy']['last_name']
where $xxx is the data you are accessing.
Hope this helps.
On Nov 18, 5:12 pm, naidim <[email protected]> wrote:
> How do you design a table and model for records which contain 2
> references (foreign keys) to the same table?
>
> e.g. users table contains users, friends table contains user1_id and
> user2_id, creating a relationship between two users.
--
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=.