diff options
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/merger.rb | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 26 |
2 files changed, 5 insertions, 32 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 0a5e9ef171..1c2a06328f 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -17,16 +17,7 @@ module ActiveRecord end def merge - HashMerger.new(relation, other_hash).merge - end - - private - - def other_hash - hash = {} - Relation::MULTI_VALUE_METHODS.map { |name| hash[name] = other.send("#{name}_values") } - Relation::SINGLE_VALUE_METHODS.map { |name| hash[name] = other.send("#{name}_value") } - hash + HashMerger.new(relation, other.values).merge end end diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index a365b5723b..7bf9c16959 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -1,4 +1,6 @@ require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/hash/except' +require 'active_support/core_ext/hash/slice' require 'active_record/relation/merger' module ActiveRecord @@ -29,19 +31,9 @@ module ActiveRecord # Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order # def except(*skips) - result = self.class.new(@klass, table) + result = self.class.new(@klass, table, values.except(*skips)) result.default_scoped = default_scoped - - (Relation::MULTI_VALUE_METHODS - skips).each do |method| - result.send(:"#{method}_values=", send(:"#{method}_values")) - end - - (Relation::SINGLE_VALUE_METHODS - skips).each do |method| - result.send(:"#{method}_value=", send(:"#{method}_value")) - end - result.extend(*extending_values) if extending_values.any? - result end @@ -53,19 +45,9 @@ module ActiveRecord # Post.order('id asc').only(:where, :order) # uses the specified order # def only(*onlies) - result = self.class.new(@klass, table) + result = self.class.new(@klass, table, values.slice(*onlies)) result.default_scoped = default_scoped - - (Relation::MULTI_VALUE_METHODS & onlies).each do |method| - result.send(:"#{method}_values=", send(:"#{method}_values")) - end - - (Relation::SINGLE_VALUE_METHODS & onlies).each do |method| - result.send(:"#{method}_value=", send(:"#{method}_value")) - end - result.extend(*extending_values) if extending_values.any? - result end |