On Feb 13, 10:23 am, Marnen Laibow-Koser <[email protected]> wrote: > On Feb 12, 3:11 pm, Josh Traxton <[email protected]> > wrote: [...] > > User.rb > > # A User can participate in many runs and during the run will be buying > > Items (or maybe buying a fraction of 1 item). > > has_many :runs > > has_many :items, :through => :participations #This is my area of > > question > > Why do you need a :through at all here? has_many :items should be > sufficient, if I understand the situation correctly. [...]
Aack! Right after posting that, I realized something else. If a User can participate in many Runs, and a Run can have many Users associated with it, then you need class Run has_and_belongs_to_many :users end class User has_and_belongs_to_many :runs end That will create a join table (called runs_users) associating Users with Runs. The join table will not be able to hold any additional information, and will not be associated with an ActiveRecord model type. If you need the join to hold additional information or be an ActiveRecord subclass, that's what has_many :through is for. In other words, has_and_belongs_to_many is kind of a special case of the simplest type of has_many :through. Does that help? Best, -- Marnen Laibow-Koser [email protected] http://www.marnen.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

