From: Pedro Santos Date: 2005-02-13T20:04:59+09:00 Subject: Re: Rails: has_and_belongs_to_many Thanks, I had missed the collection.push_with_attributes(object, join_attributes) method in the "has_and_belongs_to_many" meta-method description. Pedro in article dcedf5e205021219371950808d@mail.gmail.com, Cameron McBride at cameron.mcbride@gmail.com wrote on 05/02/13 3:38 AM: > Greetings, > >> I am experimenting with Rails, and I have the following question regarding >> ActiveRecord. > > first off, the rails list might usually be more helpful (quicker) with > rails questions rather than ruby-talk. > >> If I want to model a situation where a many to many relationship has some >> fields associated with it, is there any way to do it with ActiveRecord? >> >> For instance, if several stores have product inventory I would have a many >> to many relation between the "products" table and the "stores" table, with >> the quantity stored in the table "stores_products". > > um, yes. but like your subject says, it's the > has_and_belongs_to_many part that does EXACTLY what you're talking > about. in good faith, here is the link: > http://ar.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html# > M000011 > > or look at the 'associations.rb' in the examples directory of AR. > > Cameron > >