gpt4 book ai didi

php - CakePHP 发现未在查询中插入正确的引号

转载 作者:行者123 更新时间:2023-11-29 12:44:56 25 4
gpt4 key购买 nike

我使用此代码来创建卡车类型列表,并按类型进行计数和排序。

$count['type'] = $this->Type->find('all',
array('joins' => array(
array(
'table' => 'truck_has_types',
'alias' => 'TruckHasTypes',
'type' => 'LEFT',
'conditions' => array(
'Type.id' => 'TruckHasTypes.types_id',
)
)
),
'fields' => array(
'Type.id',
'Type.name',
'COUNT(TruckHasTypes.types_id) as N'),
'group' => 'TruckHasTypes.types_id'
)
);

即使认为应该有更多结果,查询也只返回一个结果。我找到了罪魁祸首。查询如下所示(从 sql_dump 获取)

SELECT `Type`.`id`, `Type`.`name`, COUNT(`TruckHasTypes`.`types_id`) as N FROM `douglass_cake`.`types` AS `Type` LEFT JOIN `douglass_cake`.`truck_has_types` AS `TruckHasTypes` ON (`Type`.`id` = 'TruckHasTypes.types_id') WHERE 1 = 1 GROUP BY `TruckHasTypes`.`types_id`

你可以看到

ON (`Type`.`id` = 'TruckHasTypes.types_id')

没有与

相同的引号
ON (`Type`.`id` = `TruckHasTypes`.`types_id`)

我已经在 phpmyadmin 中手动添加了这些引号并且查询成功,但我无法让 cakephp 自动生成此查询。有什么想法吗?

谢谢!瑞安

最佳答案

这样做:

$count['type'] = $this->Type->find('all',
array(
'joins' => array(
array(
'table' => 'truck_has_types',
'alias' => 'TruckHasTypes',
'type' => 'LEFT',
'conditions' => array(
'Type.id=TruckHasTypes.types_id',
)
)
),
'fields' => array(
'Type.id',
'Type.name',
'COUNT(TruckHasTypes.types_id) as N'
),
'group' => 'TruckHasTypes.types_id'
)
);

关于php - CakePHP 发现未在查询中插入正确的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25585860/

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