diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-24 11:53:52 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-24 11:53:52 -0800 |
commit | 99d3ec5b1eeb33089b71355f7e45c242b576a8f0 (patch) | |
tree | 2ff2932ce83c75cd5f99a0b894252c0b412b6bed | |
parent | aff623254c3e1480eccf15e0f671404838aa327a (diff) | |
parent | 4ef75b63db314dce9e0c1a310ef3680b622bcf04 (diff) | |
download | rails-99d3ec5b1eeb33089b71355f7e45c242b576a8f0.tar.gz rails-99d3ec5b1eeb33089b71355f7e45c242b576a8f0.tar.bz2 rails-99d3ec5b1eeb33089b71355f7e45c242b576a8f0.zip |
Merge pull request #9391 from senny/8663_broken_hmt_ordering_with_includes
don't apply invalid ordering when preloading hmt associations.
-rw-r--r-- | activerecord/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/through_association.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 5 |
3 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 8317e4e2f5..5521a1579a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,11 @@ ## Rails 4.0.0 (unreleased) ## +* Preloading ordered `has_many :through` associations does no longer + apply invalid ordering to the `:through` association. + Fixes #8663. + + *Yves Senn* + * The auto explain feature has been removed. This feature was activated by configuring `config.active_record.auto_explain_threshold_in_seconds`. The configuration option was deprecated and has no more effect. diff --git a/activerecord/lib/active_record/associations/preloader/through_association.rb b/activerecord/lib/active_record/associations/preloader/through_association.rb index b0b1c13b0d..c4b50ab306 100644 --- a/activerecord/lib/active_record/associations/preloader/through_association.rb +++ b/activerecord/lib/active_record/associations/preloader/through_association.rb @@ -47,12 +47,12 @@ module ActiveRecord through_scope.where! reflection.foreign_type => options[:source_type] else unless reflection_scope.where_values.empty? - through_scope.includes_values = reflection_scope.values[:includes] || options[:source] + through_scope.includes_values = Array(reflection_scope.values[:includes] || options[:source]) through_scope.where_values = reflection_scope.values[:where] end - through_scope.order! reflection_scope.values[:order] through_scope.references! reflection_scope.values[:references] + through_scope.order! reflection_scope.values[:order] if through_scope.eager_loading? end through_scope diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 3bf9125013..46f3c38ac5 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -73,6 +73,11 @@ class EagerAssociationTest < ActiveRecord::TestCase end end + def test_has_many_through_with_order + authors = Author.includes(:favorite_authors).to_a + assert_no_queries { authors.map(&:favorite_authors) } + end + def test_with_two_tables_in_from_without_getting_double_quoted posts = Post.select("posts.*").from("authors, posts").eager_load(:comments).where("posts.author_id = authors.id").order("posts.id").to_a assert_equal 2, posts.first.comments.size |