教义生成错误的表别名的查询 [英] Doctrine generating query with wrong table alias

查看:75
本文介绍了教义生成错误的表别名的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用doctrine/orm 2.5.1做一个简单的->find().

I'm trying to do a simple ->find() using doctrine/orm 2.5.1.

查询非常简单:

$this->get('order_repository')->find(10);

但这会生成一个复杂的查询:

But this is generating a complex query:

选择s0_.number AS number_0,s0_.state AS state_1,s0_.completed_at AScompleted_at_2,s0_.items_total AS items_total_3,s0_.adjustments_total AS调整项_total_4,s0_.total AS total_5,s0_at_update_at,_sat_at_update_at. Updated_at_7,s0_.deleted_at AS Deleted_at_8,s0_.id AS id_9,s0_.expires_at AS expires_at_10,s1_.currency AS currency_11,s1_.checkout_state AS checkout_state_12,s1_.payment_state AS,付款状态AS_state_state_14,s1_. s2_.unit_price AS unit_price_16,s2_.adjustments_total AS调整_total_17,s2_total AS total_18,s2_.is_immutable AS is_immutable_19,s2_.id AS id_20,s1_.channel_id AS channel_id_id_21,s1_address_ship_id_ship_id_21,s1_address_id_id_ship_id_ship_id_ship, customer_id AS customer_id_24,s1_.offer_id AS offer_id_25,s2_.order_id AS order_id_26,s2_.variant_id AS variant_id_27 FROM sylius_order s1_ LEFT JOIN sylius_order_item s2_ ON s1_.id = s 2_.order_id WHERE(s1_.id = 10)AND(s1_.deleted_at IS NULL)'

SELECT s0_.number AS number_0, s0_.state AS state_1, s0_.completed_at AS completed_at_2, s0_.items_total AS items_total_3, s0_.adjustments_total AS adjustments_total_4, s0_.total AS total_5, s0_.created_at AS created_at_6, s0_.updated_at AS updated_at_7, s0_.deleted_at AS deleted_at_8, s0_.id AS id_9, s0_.expires_at AS expires_at_10, s1_.currency AS currency_11, s1_.checkout_state AS checkout_state_12, s1_.payment_state AS payment_state_13, s1_.shipping_state AS shipping_state_14, s2_.quantity AS quantity_15, s2_.unit_price AS unit_price_16, s2_.adjustments_total AS adjustments_total_17, s2_.total AS total_18, s2_.is_immutable AS is_immutable_19, s2_.id AS id_20, s1_.channel_id AS channel_id_21, s1_.shipping_address_id AS shipping_address_id_22, s1_.billing_address_id AS billing_address_id_23, s1_.customer_id AS customer_id_24, s1_.offer_id AS offer_id_25, s2_.order_id AS order_id_26, s2_.variant_id AS variant_id_27 FROM sylius_order s1_ LEFT JOIN sylius_order_item s2_ ON s1_.id = s2_.order_id WHERE (s1_.id = 10) AND (s1_.deleted_at IS NULL)'

出现以下错误:

SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列's0_.number'

SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.number' in 'field list'

我可以看到s0_在查询的任何地方都没有定义.这些别名是从理论上自动生成的,我只是不明白为什么要使用s0_,然后在FROM上将其跳过到s1_,而在s0_上提到了这些列.*

I can see that s0_ is not defined anywhere on the query. Those alias are automatic from doctrine, i just don't see why it's using s0_ and then skipping it to s1_ on the FROM which has the columns mentioned on s0_.*

推荐答案

我刚刚在这个问题上花了一个小时;您可能犯了与我相同的错字.

I've just spent an hour on this same problem; You probably made the same typo mistake as me.

对我来说,问题出在.yml模式定义中.在定义表之间关系的部分中,我有这个目标实体:

The problem for me was in the .yml schema definition. In the section where I defined the relations between my tables I had this target entity :

targetEntity: mlEmailNotif

代替

targetEntity: MlEmailNotif

因此,小写字母'm'使该学说为新表创建新别名(php比较区分大小写).

So the lowercase 'm' makes doctrine create a new alias for a new table (the php comparison is case sensitive).

这篇关于教义生成错误的表别名的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆