It should have been a comment, but my reputation is too low, sorry.
Unfortunately, polymorphic association is not quite the same as CTI (Inheritance of table classes): CTI requires a parent table with the same identifier for all subclasses.
CTI can work in most cases, but it can be a problem if you want to create a polymorphic relationship between existing objects that already have their own identifier and / or may have a different type of identifier.
In addition, CTI requires creating a record in the parent table for each subclass that is useless for polymorphic association. A polymorphic association should not require any table, it should just join existing tables with conditions (id, type). I believe Doctrine requires a parent table for convenience / performance.
When CTI is not a solution, I propose to emulate a polymorphic association at the repository level, i.e. create an abstract repository with the $ type attribute and implement the polyorphicJoin method, which automatically joins the current query to the target table using the id / type condition. It then extends the abstract repository with your Repositories subclasses and calls the polymorphicJoin method when necessary in your search / select methods.
It would be great if such an association were implemented in the Doctrine.
source share