2010-09-23 60 views
0

嗨,我是新的蛋糕PHP,並不能解決問題。問題是我有一張桌子,如何在Cakephp中給同一張表3關係

ID VARCHAR(16)

PARENT_ID VARCHAR(16)

文本文本

USER_ID BIGINT(20)

is_deleted_by_user位(1)

is_deleted_by_us位(1)

who_deleted BIGINT(20)

who_answered BIGINT(20)

modified_at日期時間

created_at日期時間

在這個表我想給用戶表和USER_ID之間的關係,who_deleted

, who_answered。我的意思是user_id,who_deleted和who_answered是一個用戶ID。我怎麼能給用戶表和這張表之間的關係?

回答

2

創建與同一模型的多個關係相對比較容易。有一個section of the documentation致力於它。以下是我已經做到了爲具有與Binary模型相關的多個領域的一個Resource模型:

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 ... 
} 

resources表包含pdf_file_idmsword_file_id領域,每個引用Binary記錄。

希望有所幫助。