Within the application I am building, I wish to have Occasions. People may then sign up for the big event by developing a team, by directly signing up to have an event (no team), or by joining a current team. I initially arrange it as Event has_many teams, Team has_many customers, user goes_to Team and Event. However, I anticipate problems if your registered user really wants to join another event (or team for an additional event), as well as when attempting to list out such things as @user.occasions or @user.teams within the user interface. Someone recommended utilizing a join table and developing a Registration model/migration to become listed on these. Can I've got a join model that goes to Event, Team, and User? Shall We Be Held approaching all of this wrong?
You may create a the join model Registration, making the goes_to polymorphic to ensure that it may make reference to any kind of object. Here's a good example:
class Team < ActiveRecord::Base has_many :registrations, :as => :owner end
class User < ActiveRecord::Base has_many :registrations, :as => :owner end
class Registration < ActiveRecord::Base belongs_to :owner, :polymorphic => true end
class Event < ActiveRecord::Base has_many :registrations end
... t.belongs_to :owner, :polymorphic => true t.belongs_to :event ...
Now you can try consider sign ups to determine that has registered for the event. You should use has_many :occasions, :through => :sign ups, :source => :owner to return to customers, but observe that you will find some restrictions, like has_many :proprietors, :through => :sign ups, which are addressed in plug ins like has_many_polymorphs.