diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-04-13 12:22:19 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-04-13 13:17:43 +0100 |
commit | 55ee6ed7dd22a17499b68bee786da191ce68682c (patch) | |
tree | aa4c5ff7fe16bd2665367356b085a022ae53b313 /activerecord/lib/active_record/relation/spawn_methods.rb | |
parent | f52253cbebf0124bb74925e91bcca75325eaa502 (diff) | |
download | rails-55ee6ed7dd22a17499b68bee786da191ce68682c.tar.gz rails-55ee6ed7dd22a17499b68bee786da191ce68682c.tar.bz2 rails-55ee6ed7dd22a17499b68bee786da191ce68682c.zip |
Add Relation#merge!
Diffstat (limited to 'activerecord/lib/active_record/relation/spawn_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 40af665769..a53ee01afa 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -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: |