Skip to content
This repository
Browse code

Fixed stray comma when using eager loading and ordering together from…

… has_many associations #1143

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1220 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit cdf88b7b04a1d9a928410b1c90a8f1c1bc053c89 1 parent 9282062
David Heinemeier Hansson dhh authored
5 activerecord/CHANGELOG
... ... @@ -1,3 +1,8 @@
  1 +*SVN*
  2 +
  3 +* Fixed stray comma when using eager loading and ordering together from has_many associations #1143
  4 +
  5 +
1 6 *1.10.0* (19th April, 2005)
2 7
3 8 * Added eager loading of associations as a way to solve the N+1 problem more gracefully without piggy-back queries. Example:
8 activerecord/lib/active_record/associations/has_many_association.rb
@@ -67,7 +67,13 @@ def find(*args)
67 67 end
68 68 else
69 69 options[:conditions] = @finder_sql + (options[:conditions] ? " AND #{options[:conditions]}" : "")
70   - options[:order] = options[:order] ? "#{options[:order]}, #{@options[:order]}" : @options[:order]
  70 +
  71 + if options[:order] && @options[:order]
  72 + options[:order] = "#{options[:order]}, #{@options[:order]}"
  73 + elsif @options[:order]
  74 + options[:order] = @options[:order]
  75 + end
  76 +
71 77 @association_class.find(args.size == 1 ? args.first : args, options)
72 78 end
73 79 end
2  activerecord/test/associations_go_eager_test.rb
@@ -25,7 +25,7 @@ def test_loading_with_multiple_associations
25 25 end
26 26
27 27 def test_loading_from_an_association
28   - posts = @david.posts.find(:all, :include => :comments)
  28 + posts = @david.posts.find(:all, :include => :comments, :order => "posts.id DESC")
29 29 assert_equal 2, posts.first.comments.size
30 30 end
31 31
2  activerecord/test/fixtures/post.rb
... ... @@ -1,6 +1,6 @@
1 1 class Post < ActiveRecord::Base
2 2 belongs_to :author
3   - has_many :comments
  3 + has_many :comments, :order => "body"
4 4 has_and_belongs_to_many :categories
5 5 end
6 6

0 comments on commit cdf88b7

Please sign in to comment.
Something went wrong with that request. Please try again.