Hi, I am interested in having a many-to-many relationship between products and images. Also I would like to order the images for each particular product. My database tables are like this (the id field in images_products may be unnecessary) products id name images id url images_products id product_id image_id position My idea for how to handle the related objects are a mess. I really wish I could do something like the following but I don''t think Rails would know how to handle it without an extra model for the images_products table. Class Product < ActiveRecord::Base has_and_belongs_to_many :images end Class Image < ActiveRecord::Base has_and_belongs_to_many :products acts_as_list :scope => product_id end Any ideas? Thanks, Peter
in products: has_and_belongs_to_many :images in images: has_and_belongs.to_many: products Now in the controller I believe you can say @products = Product.find(params[:id]) @images = @products.images.sort adam Peter Michaux wrote:> Hi, > > I am interested in having a many-to-many relationship between products > and images. Also I would like to order the images for each particular > product. My database tables are like this (the id field in > images_products may be unnecessary) > > products > id > name > > images > id > url > > images_products > id > product_id > image_id > position > > > My idea for how to handle the related objects are a mess. I really wish > I could do something like the following but I don''t think Rails would > know how to handle it without an extra model for the images_products table. > > Class Product < ActiveRecord::Base > has_and_belongs_to_many :images > end > > Class Image < ActiveRecord::Base > has_and_belongs_to_many :products > acts_as_list :scope => product_id > end > > Any ideas? > > Thanks, > Peter > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails