没有找到与Doctrine2的多态关联领域 [英] Not finding field in polymorphic association with Doctrine2

查看:133
本文介绍了没有找到与Doctrine2的多态关联领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多态关联(Class Table Inheritance),我需要使用DQL查询特定子类的实体,可以使用WHERE子句中的x INSTANCE OF Entity来完成。现在我需要为这个小孩类设置条件,但是我收到这个错误:



类人没有关联名为student_field_1



Person = Parent Class



Employee =子类



学生=子类

有没有办法,你以某种方式告诉学说,该人实际上是一个学生,并允许我把学生字段放在WHERE?

解决方案

如果您只是询问学生,那么为什么不这样做?

  SELECT s FROM Student s WHERE s.student_field_1 = ... 


I have a polymorphic association (Class Table Inheritance) and I need use DQL to query entities of a specific child class wich can be done using "x INSTANCE OF Entity" in WHERE clause. Now I need to put conditions specific for that child class but I get this error:

"Class Person has no association named student_field_1"

Person = Parent Class

Employee = Child class

Student = Child class

is there any way yo cast of somehow tell Doctrine that the Person is actually a Student and to allow me to put Student fields in the WHERE?

解决方案

If you're only querying students, then why don't you just do this?

SELECT s FROM Student s WHERE s.student_field_1 = ...

这篇关于没有找到与Doctrine2的多态关联领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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