diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-12-21 10:09:56 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-12-21 10:10:07 +0100 |
commit | 537ac7d6ade61e95f2b70685ff2236b7de965bab (patch) | |
tree | c6193fd9fe4255a50e46d1930a68bce9cffceb20 /activerecord/test/cases/associations | |
parent | 9c9c54abe08d86967efd3dcac1d65158a0ff74ea (diff) | |
parent | 9d21a7fc50496c1dabbf0b1ad51094a6e6dc83dc (diff) | |
download | rails-537ac7d6ade61e95f2b70685ff2236b7de965bab.tar.gz rails-537ac7d6ade61e95f2b70685ff2236b7de965bab.tar.bz2 rails-537ac7d6ade61e95f2b70685ff2236b7de965bab.zip |
Merge pull request #22486 from methyl/fix-includes-for-groupped-association
Pass group values when including association
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 874d53c51f..966789884b 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1242,6 +1242,23 @@ 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 + + preloaded = subclass.includes(:posts_ordered_by_comments_tags_count).map(&:posts_ordered_by_comments_tags_count) + loaded = subclass.all.map(&:posts_ordered_by_comments_tags_count) + assert preloaded == loaded, 'Preloaded records differ from expected result.' + end + end + test "scoping with a circular preload" do assert_equal Comment.find(1), Comment.preload(:post => :comments).scoping { Comment.find(1) } end |