From 28ef2de2292695815eace5f2645fe4e305768403 Mon Sep 17 00:00:00 2001 From: James Williams Date: Thu, 19 Apr 2018 09:27:31 -0600 Subject: Fix relation merging with skip_query_cache! --- activerecord/CHANGELOG.md | 6 +++++- activerecord/lib/active_record/relation/query_methods.rb | 4 ++-- activerecord/test/cases/relation/merging_test.rb | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index d8bf7df63b..47c2a4e990 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,4 +1,8 @@ -* Add `ActiveRecord::Base.base_class?` predicate. +* Fix relation merging with skip_query_cache! + + *James Williams* + +* Add `ActiveRecord::Base.base_class?` predicate. *Bogdan Gusiev* diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 4e60863e52..a180b0f0d3 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -894,8 +894,8 @@ module ActiveRecord self end - def skip_query_cache! # :nodoc: - self.skip_query_cache_value = true + def skip_query_cache!(value = true) # :nodoc: + self.skip_query_cache_value = value self end diff --git a/activerecord/test/cases/relation/merging_test.rb b/activerecord/test/cases/relation/merging_test.rb index 074ce9454f..f53ef1fe35 100644 --- a/activerecord/test/cases/relation/merging_test.rb +++ b/activerecord/test/cases/relation/merging_test.rb @@ -78,6 +78,10 @@ class RelationMergingTest < ActiveRecord::TestCase assert_equal 1, comments.count end + def test_relation_merging_with_skip_query_cache + assert_equal Post.all.merge(Post.all.skip_query_cache!).skip_query_cache_value, true + end + def test_relation_merging_with_association assert_queries(2) do # one for loading post, and another one merged query post = Post.where(body: "Such a lovely day").first -- cgit v1.2.3