查询构建器从 leftJoin 中选择 id
我有一个从实体获取的选择字段 我想通过选择从中选择 id 的表来完全自定义我的选择 (这里我想选择t.id
而不是tl.id
作为选择值)
return $er->createQueryBuilder('tl')
->addSelect('l')
->addSelect('t')
->leftJoin('tl.lang', 'l')
->leftJoin('tl.type', 't')
->where('l.isDefault = 1')
->orderBy('tl.name', 'ASC');
由于我的表,我不能简单地获取表t,我必须使用tl
I have a select field that fetch from an entity
and I would like to customize completely my select by choosing the table the id is picked from
(here I would like to select t.id
instead of tl.id
as the select value)
return $er->createQueryBuilder('tl')
->addSelect('l')
->addSelect('t')
->leftJoin('tl.lang', 'l')
->leftJoin('tl.type', 't')
->where('l.isDefault = 1')
->orderBy('tl.name', 'ASC');
Due to my tables, I can't simply fetch the table t, I have to use tl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的查询不符合 Doctrine 2 QueryBuilder 中定义的语法: http://www.doctrine-project.org/docs/orm/2.0/en/reference/query-builder.html
您的查询可能在 Doctrine 1.2 中有效,但在 Doctrine 2 中您应该根据我上面发布的链接中定义的语法构建您的查询。
例如,Doctrine 2 中不再使用
->addSelect('l')
。它变成了->add('select', 'l')
。Your query is not according to the syntax defined in Doctrine 2 QueryBuilder: http://www.doctrine-project.org/docs/orm/2.0/en/reference/query-builder.html
Your query might work in Doctrine 1.2 but in Doctrine 2 you should build your query according to the syntax defined in the link I posted above.
For example
->addSelect('l')
is not being used in Doctrine 2 anymore. It has become->add('select', 'l')
.您不必为列设置不同的别名。它将被水合为相关实体的列。
You don't have to set different alias for your column. It'll be hydrated as column of the related entity.