Mysql左外连接列不存在 - CodeIgniter DataMapper ORM

时间:2014-06-19 14:26:31

标签: php mysql codeigniter codeigniter-datamapper

我正在运行以下查询,该查询由CodeIgniter的DataMapper ORM生成,因为我尝试查询格式order_product/order/order_status的深层关系:

SELECT `order_products`.*
FROM (`order_products`)
LEFT OUTER JOIN `orders` orders ON `orders`.`id` = `order_products`.`order_id`
LEFT OUTER JOIN `order_statuses` order_order_statuses ON `order_order_statuses`.`id` = `orders`.`order_status_id`
WHERE `order_products`.`sku` IN ('SYB-SAMPLETEST8', 'Copy of SYB-SAMPLE#B')
AND `order_products`.`deleted` =  0
AND `orders`.`ext_created_on` >= '2014-05-05'
AND `order_products`.`deleted` =  0
AND `orders`.`ext_created_on` <= '2014-05-21'
AND `orders`.`deleted` =  0
AND `order_statuses`.`deleted` =  0
AND `order_order_statuses`.`sales_data` =  1

我收到以下错误:

ERROR 1054 (42S22): Unknown column 'order_statuses.deleted' in 'where clause'

order_statuses表的架构如下:

+-------------+--------------+------+-----+-------------------+----------------+
| Field       | Type         | Null | Key | Default           | Extra          |
+-------------+--------------+------+-----+-------------------+----------------+
| id          | int(11)      | NO   | PRI | NULL              | auto_increment |
| ext_id      | int(11)      | YES  |     | NULL              |                |
| ext_type_id | int(11)      | YES  |     | NULL              |                |
| name        | varchar(255) | YES  |     | NULL              |                |
| sales_data  | tinyint(1)   | YES  |     | 0                 |                |
| deleted     | tinyint(1)   | NO   |     | 0                 |                |
| created_on  | timestamp    | NO   |     | CURRENT_TIMESTAMP |                |
+-------------+--------------+------+-----+-------------------+----------------+

为什么即使已删除的列存在,我也会收到此错误?

1 个答案:

答案 0 :(得分:1)

因为您将其别名为order_order_statuses。