使用两个(复合)外键关系链接两个表

Linking two tables with two (composite) foreign key relation

关系

table B 中的两列与 table A 中的两列相关联。

食谱

食谱中未找到示例。 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']
    ]);

还有这个:

$this->hasMany('B1', [
        'foreignKey' => 'a_id',
        'joinType' => 'INNER',
        'className' => 'B'
    ]);

$this->hasMany('B2', [
        'foreignKey' => 'a_name',
        'joinType' => 'INNER',
        'className' => 'B'
    ]);

可以使用数组指定组合键,几乎所有地方都支持外键和主键。

$this->hasMany('B', [
    'foreignKey' => [
        'a_id',
        'a_name'
    ],
    'bindingKey' => [
        'a_id',
        'a_name'
    ]
]);

文档中的一个示例不会有什么坏处,您可能想要打开一个工单 over at GitHub

ps。 hasMany 协会不支持 joinType 选项。