2011-05-21 32 views
0

申報的關係,當我宣佈在型號 例關係::CakePHP的時候,模型

Class User extends AppModel{ 
var $name = 'User'; 
**var $hasOne = 'Myprofile';** 

Class User extends AppModel{ 
    var $name = 'User'; 
**var $hasMany = 'Reply';**  

,我必須在

Class Myprofile extends AppModel{ 
var $name ='Myprofile'; 
var $primaryKey = 'myprofileid'; 
**var $hasOne = 'User';** 


Class Reply extends AppModel{ 
var $name ='Myprofile'; 
var $primaryKey = 'myprofileid'; 
**var $belongsTo = 'User'** 

右邊申報或不

而另一位問題
用戶{
userid
名稱
}
進myWidget {
mywidgetid
widgetname
}
窗口小部件{
widgetuseid
mywidget_id
WIDGET_ID

Class Mywidget extends AppModel{ 
var $name = 'Mywidget'; 
var $primaryKey = 'mywidgetid'; 
var $hasAndBelongsToMany = array(
    'Mywidget' => array(
     'className' => 'Mywidget', 
     'joinTable' => 'Widgetuse', 
     'foreignKey' => 'user_id', 
     'associationForeignKey' => 'mywidget_id', 
     'with' => 'Widgetuse', 

right or not 
thank you for comment 

回答

0

首先,停止使用 「用戶id」 和「簡檔「作爲主鍵,改用」id「(因爲它是默認的)。

簡介belongsTo用戶,用戶hasMany回覆;回覆belongsTo用戶。

還有什麼問題?

+0

爲什麼我不使用userid replyid.other queston我必須聲明 關係在兩個模型和最後我聲明HABTMN權利或不請在我的問題中回答 – aragon 2011-05-22 01:56:33