CakePHP hasMany relationship with multiple columns
- by Muhammad Yasir
Hi,
I am using CakePHP framework to build a web application. The simplest form of my problem is this:
I have a users table and a messages table with corresponding models. Messages are sent from a user to another user. So messages table has columns from_id and to_id in it, both referencing to id of users. I am able to link Message model to User model by using $belongsTo but I am unable to link User model with Message model (in reverse direction) by using $hasMany in the same manner.
var $hasMany = array(
'From' => array(
'className' => 'Message',
'foreignKey' => 'from_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'To' => array(
'className' => 'Message',
'foreignKey' => 'to_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
What can do here? Any ideas? Thanks for any help.