diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 8 | ||||
-rw-r--r-- | activerecord/test/associations_go_eager_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/fixtures/post.rb | 2 |
4 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e212942ee6..d15ed741e5 100644 --- a/activerecord/CHANGELOG +++ b/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: diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index a775f438f3..5b0ac25d17 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -67,7 +67,13 @@ module ActiveRecord 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 diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index 8de37f3d92..20ea9656b8 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -25,7 +25,7 @@ class EagerAssociationTest < Test::Unit::TestCase 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 diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb index ce9abcc693..bac0857e5f 100644 --- a/activerecord/test/fixtures/post.rb +++ b/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 |