Relationship | Association Type | Example |
---|---|---|
one to one | hasOne | A user has one profile. |
one to many | hasMany | A user can have multiple recipes. |
many to one | belongsTo | Many recipes belong to a user. |
many to many | hasAndBelongsToMany | Recipes have, and belong to many ingredients. |
四种关联关系。
一个例子
/**
* hasOne associations
*
* @var array
*/
public $hasOne = array(
'Engine' => array(
'className' => 'Engine',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'TbAppkey' => array(
'className' => 'TbAppkey',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'UserAccount' => array(
'className' => 'UserAccount',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'UserGroup' => array(
'className' => 'UserGroup',
'foreignKey' => 'user_group_id',
'conditions' => '',
'fields' => '',
'order' => '',
'type' => 'inner'
),
'Domain' => array(
'className' => 'Engine',
'foreignKey' => 'domain_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => '',
'type' => 'inner'
)
);
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'Merchant' => array(
'className' => 'Merchant',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'UserAccessPlatform' => array(
'className' => 'UserAccessPlatform',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);