与fuelphp orm的复合关键关系

我试图让FuelPHP的orm在使用related()方法时使用复合键。

我有两个表的数据库设置,我想基于他们的复合键来关联它们。

例如,我通常会在我的orm模型中使用这样的关系:

protected static $_has_one = [
    'message_flag' => [
        'key_from' => 'object_id',
        'model_to' => 'ModelClass',
        'key_to' => 'object_id',
        'cascade_save' => false,
        'cascade_delete' => false,
    ],
];

但不是使用key_from => 'idkey_to => 'object_id ,我想加入他们的复合键,它可能看起来像这样:

protected static $_has_one = [
    'message_flag' => [
        'key_from' => ['object_id', 'other_key'],
        'model_to' => 'ModelClass',
        'key_to' => ['object_id', 'other_key',
        'cascade_save' => false,
        'cascade_delete' => false,
    ],
];

为了澄清,最好的例子是FuelPHP文档中推荐的例子,它创建了一个如下所示的查询:

SELECT `t0`.`object_id` AS `t0_c0`, `t0`.`other_key` AS `t0_c1` FROM `myTable` AS `t0` LEFT JOIN `otherTable` AS `t1` ON (`t0`.`object_id` = `t1`.`object_id`);

但是我想用ORM构建的查询看起来像这样:

SELECT `t0`.`object_id` AS `t0_c0`, `t0`.`other_key` AS `t0_c1` FROM `myTable` AS `t0` LEFT JOIN `otherTable` AS `t1` ON (`t0`.`object_id` = `t1`.`object_id` AND `t0`.`other_key` = `t1`.`other_key`);

其实,我刚刚尝试了我的希望,但没有文档上面的例子

protected static $_has_one = [
    'message_flag' => [
        'key_from' => ['object_id', 'other_key'],
        'model_to' => 'ModelClass',
        'key_to' => ['object_id', 'other_key',
        'cascade_save' => false,
        'cascade_delete' => false,
    ],
];

惊讶地说这实际上工作。 不过,如果其他人有类似的问题,我希望他们找到这个答案。

链接地址: http://www.djcxy.com/p/64815.html

上一篇: Compound key relationship with fuelphp orm

下一篇: Fuelphp ORM unexpected results when adding to model property