aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
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/test/cases
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/test/cases')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 0c09713971..622c984b3b 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1242,6 +1242,19 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal projects.last.mentor.developers.first.contracts, projects.last.developers.last.contracts
end
+ def test_eager_load_with_group_clause
+ assert_nothing_raised(ActiveRecord::StatementInvalid) do
+ subclass = Class.new(ActiveRecord::Base) do
+ def self.name; "Author"; end
+ self.table_name = "authors"
+ has_many :posts_ordered_by_comments_tags_count, -> { joins('LEFT JOIN comments ON comments.post_id = posts.id').order("SUM(comments.tags_count)").group('posts.id') }, :class_name => "Post"
+ end
+
+ posts = subclass.includes(:posts_ordered_by_comments_tags_count).first.posts_ordered_by_comments_tags_count
+ assert_equal subclass.first.posts_ordered_by_comments_tags_count, posts
+ end
+ end
+
test "scoping with a circular preload" do
assert_equal Comment.find(1), Comment.preload(:post => :comments).scoping { Comment.find(1) }
end