Can't find field in polymorphic association with Doctrine2

I have a polymorphic association (Class Inheritance) and I need to use DQL to query objects of a specific child class, which can be done using "x INSTANCE OF Entity" in the WHERE clause. Now I need to set conditions specific to this child class, but I am getting this error:

"The Person class has no association with the student_field_1 name"

Person = parent class

Employee = child class

Student = child's class

Is there any way that somehow explains the Doctrine that a Person is actually a Student and allows me to put the Student's t fields in WHERE?


source to share

2 answers

It looks like "Mapped Superclass" is more suitable for what you are trying to do as it doesn't require an explicit parent / child relationship, its simple inheritance.

With class table inheritance, you need to provide a discriminator map that links the two objects using a key.

"The table of the child class must be bound to the table of the parent class through a foreign key constraint"



If you're only asking students, why don't you just do it?

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




All Articles