diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2015-11-17 09:47:30 +0000 |
---|---|---|
committer | Andrew White <pixeltrix@users.noreply.github.com> | 2015-11-17 09:47:30 +0000 |
commit | 5e36c5057adf838368ab9268a1436bb9d5e41b88 (patch) | |
tree | 8202437ddaa85e390c537500c2298dad64341217 /activerecord | |
parent | 788d7bce3dc60fde5588df70b5131716b99680a1 (diff) | |
parent | a98475c2df8ab7d7d353cb29bb3f201c4c7eb9d1 (diff) | |
download | rails-5e36c5057adf838368ab9268a1436bb9d5e41b88.tar.gz rails-5e36c5057adf838368ab9268a1436bb9d5e41b88.tar.bz2 rails-5e36c5057adf838368ab9268a1436bb9d5e41b88.zip |
Merge pull request #22257 from yui-knk/fix_merge_to_not_call_to_proc_for_hash
Make `AR::SpawnMethods#merge!` to check an arg is a Proc
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 5c3318651a..ee509b98d4 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -12,6 +12,7 @@ module ActiveRecord # Merges in the conditions from <tt>other</tt>, if <tt>other</tt> is an ActiveRecord::Relation. # Returns an array representing the intersection of the resulting records with <tt>other</tt>, if <tt>other</tt> is an array. + # # Post.where(published: true).joins(:comments).merge( Comment.where(spam: false) ) # # Performs a single join query with both where conditions. # @@ -37,11 +38,12 @@ module ActiveRecord end def merge!(other) # :nodoc: - if !other.is_a?(Relation) && other.respond_to?(:to_proc) + if other.is_a?(Hash) + Relation::HashMerger.new(self, other).merge + elsif other.respond_to?(:to_proc) instance_exec(&other) else - klass = other.is_a?(Hash) ? Relation::HashMerger : Relation::Merger - klass.new(self, other).merge + Relation::Merger.new(self, other).merge end end diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 8794bc8043..b58052a962 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -24,6 +24,10 @@ module ActiveRecord def self.sanitize_sql_for_order(sql) sql end + + def self.arel_table + Post.arel_table + end end def test_construction |