xDs*_*xDs 2 cakephp associations cakephp-3.0
关系
表B中的两列与表A中的两列相关联.
表B - > belongsTo - >表A.
B.a_id = A.a_id
菜谱
没有在食谱中找到的例子. http://book.cakephp.org/3.0/en/orm/associations.html
我该如何指定这些关系?已经尝试过这个:
$this->hasMany('B', [
'conditions' => ['A.a_id' => 'B.a_id', 'A.a_name' => 'B.a_name']
]);
Run Code Online (Sandbox Code Playgroud)
还有这个:
$this->hasMany('B1', [
'foreignKey' => 'a_id',
'joinType' => 'INNER',
'className' => 'B'
]);
$this->hasMany('B2', [
'foreignKey' => 'a_name',
'joinType' => 'INNER',
'className' => 'B'
]);
Run Code Online (Sandbox Code Playgroud)
可以使用数组指定组合键,这对于外键以及几乎所有地方的主键都是支持的.
$this->hasMany('B', [
'foreignKey' => [
'a_id',
'a_name'
],
'bindingKey' => [
'a_id',
'a_name'
]
]);
Run Code Online (Sandbox Code Playgroud)
文档中的一个例子不会受到影响,你可能想在GitHub上打开一张票.
PS.hasMany协会不支持joinType选项.
| 归档时间: |
|
| 查看次数: |
1332 次 |
| 最近记录: |