原则 2 - 如何在 where 子句中使用鉴别器列
我在这样的 where 子句中使用了鉴别器列:
//f = root entity
$qb = $this->createQueryBuilder('f');
$qb->add('where', 'f.format = \'image\' OR f.format = \'text\'');
我收到错误:“消息:[语义错误]第 0 行,第 73 列靠近 'format = 'image'':错误:类 Entities\File\AbstractFile 没有字段或关联命名格式”
如何在 where 子句中使用鉴别器列?
谢谢。
I was used discriminator column in where clause like this:
//f = root entity
$qb = $this->createQueryBuilder('f');
$qb->add('where', 'f.format = \'image\' OR f.format = \'text\'');
I've got an error: "Message: [Semantical Error] line 0, col 73 near 'format = 'image'': Error: Class Entities\File\AbstractFile has no field or association named format"
How can i use discriminator column in where clause?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为你应该使用 实例
I think that you should use INSTANCE OF
它在查询生成器中看起来像这样:
注意:您将无法将类设置为参数,因为它将被转义。
It would look in query builder like this:
Note: that you will not be able to set the class as a parameter because it will be escaped.
对于 PHP 5.50 及以上版本:
for PHP 5.50 and above:
作为最新的学说版本,支持直接查询鉴别器值。
将有一个带有此子句的结果查询:
As this latest doctrine version it is supported to query directly the discriminator value.
will have a result query with this clause:
这个学说扩展对我来说非常有用,因为我需要访问父类,而
INSTANCE OF
在这种情况下不起作用。https://gist.github.com/jasonhofer/8420677
例如:我有以下内容类结构:
BaseClass
Class1 继承自 BaseClass (discriminator = c1)
Class2 继承来自 Class1 (discriminator = c2)
Class3 继承自 Class1 (discriminator = c3)
我想选择 Class1 中的所有实体strong> 但不是来自 Class2 或 Class3
This doctrine extension was very useful for me because I needed to access the parent class and
INSTANCE OF
doesn't works in that case.https://gist.github.com/jasonhofer/8420677
For example: I have the following class structure:
BaseClass
Class1 inherits from BaseClass (discriminator = c1)
Class2 inherits from Class1 (discriminator = c2)
Class3 inherits from Class1 (discriminator = c3)
I want to select all entities from Class1 but not from Class2 or Class3
您所需要的一切:
All you need: