gpt4 book ai didi

php - CakePHP 在查找查询中连接表

转载 作者:行者123 更新时间:2023-11-30 22:09:36 24 4
gpt4 key购买 nike

我有工作职位模型。它在数据库中与具有 belongsTo 关系的订单链接。因此,我需要根据与订单模型相关的条件找到具体的工作职位。所以,当我使用例如糟糕的发现时:

$workpositions = $this->Workposition->find('all', array(
'conditions' => array(
'Order.type' => 'N'
)
));

CakePHP 理解 Order.id 符号。但是当我尝试使用连接表时:

$workpositions = $this->Workposition->find('all', array(
'conditions' => array(
'Order.type' => 'N'
)
'joins' => array(
array('table' => 'ordergroups_orders',
'alias' => 'OrdergroupsOrder',
'type' => 'INNER',
'conditions' => array(
'Order.id = OrdergroupsOrder.order_id',
'OrdergroupsOrder.ordergroup_id' => '3',
)
)
)));

它给我一个错误:Column not found: 1054 Unknown column 'Order.id' in 'on clause'。所以它不理解 Order.id 符号。可能是什么问题?

我也试过做这样的东西:

$workpositions = $this->Workposition->find('all', array(
'conditions' => $conditions,
'joins' => array(
array('table' => 'orders',
'alias' => 'Orders',
'type' => 'INNER',
),
array('table' => 'ordergroups_orders',
'alias' => 'OrdergroupsOrder',
'type' => 'INNER',
'conditions' => array(
'Orders.id = OrdergroupsOrder.order_id',
'OrdergroupsOrder.ordergroup_id' => $ordergroup_ids,
)
)
)));

但我收到错误 Column not found: 1054 Unknown column 'Array' in 'on clause'(Array to string conversion)。所以它不会理解我的 id 数组,而当 find 方法看到 Order 时,它会在没有绑定(bind) Order 模型的情况下理解它。

最佳答案

连接条件必须是数组值,不能是key => value。

尝试换行

'OrdergroupsOrder.ordergroup_id' => $ordergroup_ids, 

'OrdergroupsOrder.ordergroup_id = $ordergroup_ids',

$ordergroup_ids 是一个数组?尝试使用单个 ID。

关于php - CakePHP 在查找查询中连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526556/

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