gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:26:24 25 4
gpt4 key购买 nike

  • 版本:3.2.1

  • 关系

    表B中的两列与表A中的两列相关联。
  • 表A-> hasMany->表B
  • 表B->属于--表A
  • B.a_id = A.a_id
  • B.a_name = A.a_name

  • 食谱

    在食谱中找不到示例。
    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选项。

    关于cakephp - 用两个(复合)外键关系链接两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37658120/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com