-
-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] manyToMany polymorphic #434
Comments
Guys come on, let me know please if polymorphic relationships are possible with Fluent |
I have not used this part of laravel-doctrine, sorry :/ |
@marcosdipaolo You don't need the PostTag mapping. Remove it and then link Post to AbstractTag directly. You would then need to implement entity level validation to keep only PostTags within a Post. The relationship is then a straight forward many-to-many Post to AbstractTag with the type on the Tags table. As an aside, to the best of my knowledge Doctrine does not use or support "pivot" tables on many-to-many relationships. A pivot created in this way is really a missing object in your object graph. To do this in Doctrine you have to define that object and map it accordingly. The route you should take largely depends on where you want that tag type to be set: either a single object "Tag" that is mapped through a polymorphic TagRelationship object (PostTag, VideoTag etc etc) which would then give you an intermediary object and a link table with the type on it. Tag would become a first class object (not abstract) and the link table would become a first class object in between the Post and Tag. Or: as originally stated, Tag has the type and Post has a collection of AbstractTag objects that you would need to enforce the type of via application logic. There would be no type field on the link table between tag and post. |
Thanks @dave-redfern |
I know this place is for bugs, but i don't know any other place where to get a clear response about this.
I'm mantaining a huge app that uses Doctrine with
LaravelDoctrine
andFluent
.I already used Mapping inheritance a couple of times but I dont know how to achieve a manyToMany polymorphic relationship and could't find anything at the docs.
Let's do this with
Tags
:I have an:
then:
and:
What i've tried so far is a mix between a normal
belongsToMany
relationship at the child mappings with thesingleTableInheritance
method at the parent's mapping.and is saving the tags at the
tags
table but not the relationship at the pivot. I don't even know if it should create one pivot for every child or not.In short, i need help, thanks a lot and excuse me if this is not the place
The text was updated successfully, but these errors were encountered: