views:

24

answers:

1

Hi i am new in cake php and can't solve the problem. The 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?

Thanx

+2  A: 

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.

Rob Wilkerson