aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-02-15 08:57:33 +0100
committerYves Senn <yves.senn@gmail.com>2013-02-24 20:51:39 +0100
commit4ef75b63db314dce9e0c1a310ef3680b622bcf04 (patch)
treeece75f1a4b1dc1f1c65ffc3350da6dd0613a1792 /activerecord/lib
parentd65376fce4ea806e489d1fb985bc9393bcd2e0e2 (diff)
downloadrails-4ef75b63db314dce9e0c1a310ef3680b622bcf04.tar.gz
rails-4ef75b63db314dce9e0c1a310ef3680b622bcf04.tar.bz2
rails-4ef75b63db314dce9e0c1a310ef3680b622bcf04.zip
don't apply invalid ordering when preloading hmt associations.
closes #8663. When preloading a hmt association there two possible scenarios: 1.) preload with 2 queries: first hm association, then hmt with id IN () 2.) preload with join: hmt association is loaded with a join on the hm association The bug was happening in scenario 1.) with a normal order clause on the hmt association. The ordering was also applied when loading the hm association, which resulted in the error. This patch only applies the ordering the the hm-relation if we are performing a join (2). Otherwise the order will only appear in the second query (1).
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/preloader/through_association.rb4
1 files changed, 2 insertions, 2 deletions
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