tags:

views:

32

answers:

1

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 there a situation when both are appropriate? I would expect some of the behaviors to conflict...

+1  A: 

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.

deceze
Makes sense - thanks!
BWelfel