提交 5e36c505 编写于 作者: A Andrew White

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
...@@ -12,6 +12,7 @@ def spawn #:nodoc: ...@@ -12,6 +12,7 @@ def spawn #:nodoc:
# Merges in the conditions from <tt>other</tt>, if <tt>other</tt> is an ActiveRecord::Relation. # 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. # 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) ) # Post.where(published: true).joins(:comments).merge( Comment.where(spam: false) )
# # Performs a single join query with both where conditions. # # Performs a single join query with both where conditions.
# #
...@@ -37,11 +38,12 @@ def merge(other) ...@@ -37,11 +38,12 @@ def merge(other)
end end
def merge!(other) # :nodoc: 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) instance_exec(&other)
else else
klass = other.is_a?(Hash) ? Relation::HashMerger : Relation::Merger Relation::Merger.new(self, other).merge
klass.new(self, other).merge
end end
end end
......
...@@ -24,6 +24,10 @@ def self.table_name ...@@ -24,6 +24,10 @@ def self.table_name
def self.sanitize_sql_for_order(sql) def self.sanitize_sql_for_order(sql)
sql sql
end end
def self.arel_table
Post.arel_table
end
end end
def test_construction def test_construction
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册