mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Association mappings on mapped superclasses #5305
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sandermarechal on GitHub (Oct 26, 2016).
I would like to propose a feature for the ORM: Allow all association mappings on mapped superclasses, just defer definition of the targetEntity.
Here is my problem. I am writing a library/bundle/module that contains a bunch of abstract classes that represent entities. The user of this library should extend these classes to create their entities. A good practical example is the FOSUserBundle which contains abstract implementations for users and groups.
I want to provide mapping information along with these abstract classes, so I use Mapped Superclass. This allows me to provide mapping information for all fields, but it does not allow mapping information about the assocations between the classes. The target-entity is not known in my library so it is impossible to provide mapping information.
The problem is that an association mapping contains much more information than just the target-entity, and I want to provide mapping for all the other options. I want to specify the join column, database-level cascades, nullability, mapped-by and inversed-by information, etc. Everything except for the target-entity. This is currently impossible. I can only document how the relation should look and hope that the users of my library don't forget anything.
It would be great if I could provide all the information with the mapped superclass. Here is an example using users and groups:
A user of this library would only have to provide a very basic mapping:
This would make it much easier to use my library and leave less room for bugs in my user's code.
I also suggest that Doctrine checks that the target-entity is not set on a mapped superclass, so this should throw a mapping exception:
What do you think? I think it would solve a common problem..