I have got two models, User and Event. I need two kind of relationship between User and Event.
- User (:as organizer) <——-> Event, many to many relationship
- User (:as attendee) <——-> Event, many to many relationship
I am guessing if two different has_many_and_belongs_to association with polymorphism can be used to implement the relations. I am new to rails so I would appreciate any help regarding the problem.
You will not need a polymorphic relationship for this.
To define two associations between two models, you can do something like:
This will give you a one to many relationship.
If you need many to many, you’ll need a join table for each association.
And something similar for the event organizer association.
See my question here