开发者

When baking a model with CakePHP, why does it prompt for hasOne if it asked hasMany and received an answer of yes already?

开发者 https://www.devze.com 2023-01-02 00:03 出处:网络
When baking a model with CakePHP, why does it prompt for hasOne if it asked hasMany and received an answer of yes already? Is it 开发者_Go百科there a situation when both are appropriate? I would expec

When baking a model with CakePHP, why does it prompt for hasOne if it asked hasMany and received an answer of yes already? Is it 开发者_Go百科there a situation when both are appropriate? I would expect some of the behaviors to conflict...


You may hypothetically have a "primary" hasMany related model which you want quick access to, something like:

var $hasMany = array('Address');
var $hasOne = array(
    'PrimaryAddress' => array(
        'className' => 'Address',
        'conditions' => array('PrimaryAddress.type' => 'primary')
    )
);

The reason why bake asks you twice is probably primarily because nobody bothered to implement a check of whether you already selected a hasMany or not, or because they consciously decided to leave the door open for the above case.

0

精彩评论

暂无评论...
验证码 换一张
取 消