1
votes

Can someone explain me what the following 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

1 Answers

3
votes
  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.