aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorLucjan Suski <lucjansuski@gmail.com>2015-12-15 14:32:34 +0100
committerLucjan Suski <lucjansuski@gmail.com>2015-12-15 17:58:57 +0100
commit9d21a7fc50496c1dabbf0b1ad51094a6e6dc83dc (patch)
tree56d3409e2d97485c9e739f8e1891c7445b4cdf0d /activerecord/lib
parente73fe1dd8c2740ae29e7a7f48d71a62b46e6b49d (diff)
downloadrails-9d21a7fc50496c1dabbf0b1ad51094a6e6dc83dc.tar.gz
rails-9d21a7fc50496c1dabbf0b1ad51094a6e6dc83dc.tar.bz2
rails-9d21a7fc50496c1dabbf0b1ad51094a6e6dc83dc.zip
Pass SQL group by values when including scoped association
Fixes problem when added `group()` in association scope was lost in eager loaded association.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/preloader/association.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb
index e11a5cfb8a..91e7f90739 100644
--- a/activerecord/lib/active_record/associations/preloader/association.rb
+++ b/activerecord/lib/active_record/associations/preloader/association.rb
@@ -107,7 +107,7 @@ module ActiveRecord
@preloaded_records = slices.flat_map do |slice|
records_for(slice)
end
- @preloaded_records.group_by do |record|
+ @preloaded_records.group_by do |record|
convert_key(record[association_key_name])
end
end
@@ -139,6 +139,10 @@ module ActiveRecord
scope.order!(order_values)
end
+ if group_values = preload_values[:group] || values[:group]
+ scope.group!(group_values)
+ end
+
if preload_values[:reordering] || values[:reordering]
scope.reordering_value = true
end