CakePHP hasMany relationship with multiple columns

Posted by Muhammad Yasir on Stack Overflow See other posts from Stack Overflow or by Muhammad Yasir
Published on 2010-05-13T07:03:54Z Indexed on 2010/05/13 9:14 UTC
Read the original article Hit count: 272

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about cakephp

Related posts about many