say you have 3 models : user, hair_color, and eye_color
user hasOne hair_color user also hasOne eye_color
however
var $hasOne = 'hair_color';
var $hasOne = 'eye_color';
obviously wont work. So how do you implement many hasOne relationships in a single model?
I assume the answer is in the cookbook, Im going over that area now, I suspect it has something to do with passing an array to $hasOne, but no example of doing this.
var $hasOne = array('HairColor', 'EyeColor');
// hasOne is an array of model names **not file names**
OR
var $hasOne = array(
'HairColor' => array(
'className' => 'HairColor',
...
),
'EyeColor' => array(
'className' => 'EyeColor',
...
)
);
You should read manual http://book.cakephp.org/view/80/hasOne
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With