Alex Wayne
2006-Jul-28 20:01 UTC
[Rails] has_many :through with :order column on the join model
I have a model like so class Product < ActiveRecord::Base has_many :image_links, :order => :position has_many :product_images, :order => ''image_links.position'', :through => :image_links end The problem is that :order clause just gets ignored. How do you server records in a specific order when the order column is on the join model? @product.product_images produces this SQL: SELECT product_images.id, product_images.created_at FROM product_images INNER JOIN image_links ON product_images.id = image_links.product_image_id WHERE (image_links.product_id = 1) ORDER BY image_links.position Whats the problem here? -- Posted via http://www.ruby-forum.com/.
Alex Wayne
2006-Jul-28 21:42 UTC
[Rails] Re: has_many :through with :order column on the join model
Alex Wayne wrote:> I have a model like so > > class Product < ActiveRecord::Base > has_many :image_links, :order => :position > has_many :product_images, > :order => ''image_links.position'', > :through => :image_links > end > > The problem is that :order clause just gets ignored. How do you server > records in a specific order when the order column is on the join model? > > @product.product_images produces this SQL: > > SELECT product_images.id, product_images.created_at FROM product_images > INNER JOIN image_links ON product_images.id = > image_links.product_image_id WHERE (image_links.product_id = 1) ORDER BY > image_links.position > > Whats the problem here?Ok, it was apparently working jsut fine and I had a bad test. Color me embarrased. -- Posted via http://www.ruby-forum.com/.
Stephen Gerstacker
2006-Jul-28 21:47 UTC
[Rails] has_many :through with :order column on the join model
I believe that this is covered by ticket #3438 http://dev.rubyonrails.org/ticket/3438 Stephen Gerstacker -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Alex Wayne Sent: Friday, July 28, 2006 16:02 To: rails@lists.rubyonrails.org Subject: [Rails] has_many :through with :order column on the join model I have a model like so class Product < ActiveRecord::Base has_many :image_links, :order => :position has_many :product_images, :order => ''image_links.position'', :through => :image_links end The problem is that :order clause just gets ignored. How do you server records in a specific order when the order column is on the join model? @product.product_images produces this SQL: SELECT product_images.id, product_images.created_at FROM product_images INNER JOIN image_links ON product_images.id = image_links.product_image_id WHERE (image_links.product_id = 1) ORDER BY image_links.position Whats the problem here? -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails