Skip to content
Browse files

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...
1 parent 9282062 commit cdf88b7b04a1d9a928410b1c90a8f1c1bc053c89 @dhh dhh committed Apr 19, 2005
View
5 activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Fixed stray comma when using eager loading and ordering together from has_many associations #1143
+
+
*1.10.0* (19th April, 2005)
* Added eager loading of associations as a way to solve the N+1 problem more gracefully without piggy-back queries. Example:
View
8 activerecord/lib/active_record/associations/has_many_association.rb
@@ -67,7 +67,13 @@ def find(*args)
end
else
options[:conditions] = @finder_sql + (options[:conditions] ? " AND #{options[:conditions]}" : "")
- options[:order] = options[:order] ? "#{options[:order]}, #{@options[:order]}" : @options[:order]
+
+ if options[:order] && @options[:order]
+ options[:order] = "#{options[:order]}, #{@options[:order]}"
+ elsif @options[:order]
+ options[:order] = @options[:order]
+ end
+
@association_class.find(args.size == 1 ? args.first : args, options)
end
end
View
2 activerecord/test/associations_go_eager_test.rb
@@ -25,7 +25,7 @@ def test_loading_with_multiple_associations
end
def test_loading_from_an_association
- posts = @david.posts.find(:all, :include => :comments)
+ posts = @david.posts.find(:all, :include => :comments, :order => "posts.id DESC")
assert_equal 2, posts.first.comments.size
end
View
2 activerecord/test/fixtures/post.rb
@@ -1,6 +1,6 @@
class Post < ActiveRecord::Base
belongs_to :author
- has_many :comments
+ has_many :comments, :order => "body"
has_and_belongs_to_many :categories
end

0 comments on commit cdf88b7

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