CakePHP Association is not working with userdata to userdatatype
I am currently developing a webapp containing some userdata. I have the following tables:
users - contains basic userdata. userdata - contains large amount of different information about the user. userdatatype - contains definition for the different userdata.
In CakePHP i am using the hasMany association in the user model to retrieve the userdata information (wich works fine) and in the userdata model i want to use the hasOne association to retrieve the corresponding userdatatype information. But this is not working as userdatatype obviously has no userdata_id as it is the definition for the userdata.
I tried to set the foreignKey to false in the hasOne association and work with the condition 'Userdatatype.id => ??'
but i don't know how to access the instance. How do i link this models together without to much overhead in my code? Do i really need to loop trough the userdata array and establish the connection by hand?
public $hasOne = array(
'Userdatatype' => array(
'className' => 'Userdatatype',
'foreignkey' => false,
'conditions' => array('Userdatatype.id' = WHAT DO I SET HERE?)
)
);
Tables: users, userdatas, userdatatypes.
users -> id, email, name etc.
userdatas -> id, user_id, data1, data2, data3 etc.
userdatatypes -> id, userdata_id, type
**Model User.php :**
public $hasMany = array('Userdata');
**Model Userdata.php :**
public $belongsTo = array('User');
public $hasOne = array('Userdatatype');
**Model Userdatatype.php :**
public $belongsTo = array('Userdata');
如果我正确地理解了这个问题,这应该将你的模型链接在一起。
链接地址: http://www.djcxy.com/p/64892.html上一篇: 更改数据框的列名称