I use the CakePHP framework to build a web application. The simplest form of my problem is this:
I have a user table and a message table with the corresponding models. Messages are sent from the user to another user. Thus, the message table contains the columns from_id and to_id in it, referring to the user ID. I can associate a message model with a user model using $ belongsTo, but I cannot associate a User model with a message model (in the opposite direction) using $ hasMany in the same way.
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 be done here? Any ideas? Thanks for any help.
source
share