is it possible to use kind of polymorphic association to different owner objects in Doctrine 2? I mean that for example ImageGroup entity is owned by different entities: Article, Album, Post, Comment, etc. So there should be "ownerId" and "ownerType" attributes in ImageGroup table, where "ownerType" is discriminator.
I am already using Class Table Inheritance and also Superclass mapping on other object relationships in my project, but any of them suits for this problem, if I am correct. Because in these situations referred objects are inherited.
I have read answers to polymorphic associations here, but I found no answer to my example.
In my example is no inheritance at all. Any help, please? Thanks in advance!
What you are looking for is the strategy pattern, which basically allows you to have a weak link between your objects and the ones you want to reference, such as ['name' => 'EntityName', 'identifier' => 123]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With