mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add Relation#merge!
This commit is contained in:
parent
f52253cbeb
commit
55ee6ed7dd
2 changed files with 17 additions and 9 deletions
|
@ -4,20 +4,23 @@ require 'active_record/relation/merger'
|
|||
module ActiveRecord
|
||||
module SpawnMethods
|
||||
def merge(other)
|
||||
if other
|
||||
case other
|
||||
when Array
|
||||
to_a & other
|
||||
when Hash
|
||||
Relation::HashMerger.new(clone, other).merge
|
||||
else
|
||||
Relation::Merger.new(clone, other).merge
|
||||
end
|
||||
if other.is_a?(Array)
|
||||
to_a & other
|
||||
elsif other
|
||||
clone.merge!(other)
|
||||
else
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
def merge!(other)
|
||||
if other.is_a?(Hash)
|
||||
Relation::HashMerger.new(self, other).merge
|
||||
else
|
||||
Relation::Merger.new(self, other).merge
|
||||
end
|
||||
end
|
||||
|
||||
# Removes from the query the condition(s) specified in +skips+.
|
||||
#
|
||||
# Example:
|
||||
|
|
|
@ -206,5 +206,10 @@ module ActiveRecord
|
|||
assert relation.create_with!(foo: 'bar').equal?(relation)
|
||||
assert_equal({foo: 'bar'}, relation.create_with_value)
|
||||
end
|
||||
|
||||
test 'merge!' do
|
||||
assert relation.merge!(where: ['foo']).equal?(relation)
|
||||
assert_equal ['foo'], relation.where_values
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue