Not finding field in polymorphic association with Doctrine2

蓝咒 提交于 2019-12-23 19:46:34

问题


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?


回答1:


It sounds like a "Mapped Superclass" would be more suited to what your trying to do as it doesn't require an explicit link between parent / child, its just simple inheritance.

http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/inheritance-mapping.html#mapped-superclasses

With Class Table Inheritance your required to provide discriminator map that links the two entities through a key.

"The table of a child class should be linked to the table of a parent class through a foreign key constraint"




回答2:


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

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


来源:https://stackoverflow.com/questions/9834842/not-finding-field-in-polymorphic-association-with-doctrine2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!