开发者

CakePHP Model BelongsTo

Can someone explain me what the fo开发者_高级运维llowing means ?

var $belongsTo = array(
    '**EventOrganiser**' => array(
        'className' => '**EventOrganiser**',
        'foreignKey' => '**event_organiser_id**',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);

i have marked the content with Content in the code. What does each of the EventOrganiser refer to ?


  1. The association name:

    $belongsTo = array(
        'EventOrganiser' => array(
    

    This is the name the association will be accessibly as from the model:

    $this->Foo->EventOrganizer->...
    
    array(
        'Foo' => array(
           ...
        ),
        'EventOrganizer' => array(
           ...
        )
    )
    

    This is a completely freeform name, you can name it whatever you want. It will reflect in query results when searched from this model and when accessing the related model from this model.

  2. The class name:

    'className' => 'EventOrganiser',
    

    That's the class name, the actual model name, that shall be used for the related model.

  3. The foreign key:

    'foreignKey' => 'event_organiser_id',
    

    That's the foreign key column name in the database that shall be used for this association.

The latter two are not freeform, they need to be correct. Cake can usually guess them based on naming conventions of the association name.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜