开发者

How to give 3 relations to same table in Cakephp

开发者 https://www.devze.com 2023-01-17 19:19 出处:网络
Hi i am new in cake php and can\'t solve the problem. Th开发者_StackOverflow社区e problem is I have a table like;

Hi i am new in cake php and can't solve the problem. Th开发者_StackOverflow社区e problem is I have a table like;

id varchar(16)

parent_id varchar(16)

text text

user_id bigint(20)

is_deleted_by_user bit(1)

is_deleted_by_us bit(1)

who_deleted bigint(20)

who_answered bigint(20)

modified_at datetime

created_at datetime

in this table i want to give relations between users table and user_id, who_deleted, who_answered. I mean user_id, who_deleted and who_answered are one user id. How can i give relations between users table and this table?


It's relatively easy to create multiple relationships to the same model. There's a section of the documentation dedicated to it. Here's how I've done it for a Resource model that has multiple fields associated with a Binary model:

class Resource extends AppModel {
  public $belongsTo = array ( 
    'PDF' => array (
      'className'  => 'Binary',
      'foreignKey' => 'pdf_file_id'
    ),
    'MSWord' => array (
      'className'  => 'Binary',
      'foreignKey' => 'msword_file_id'
    )
  );

  ... other class code ...
}

The resources table contains pdf_file_id and msword_file_id fields which each reference a Binary record.

Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消