aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/spawn_methods.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/relation/spawn_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb33
1 files changed, 8 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index d5b13c6100..cccf413e67 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -1,17 +1,7 @@
module ActiveRecord
module SpawnMethods
- def spawn(arel_table = self.table)
- relation = self.class.new(@klass, arel_table)
-
- (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS).each do |query_method|
- relation.send(:"#{query_method}_values=", send(:"#{query_method}_values"))
- end
-
- Relation::SINGLE_VALUE_METHODS.each do |query_method|
- relation.send(:"#{query_method}_value=", send(:"#{query_method}_value"))
- end
-
- relation
+ def spawn
+ clone.reset
end
def merge(r)
@@ -98,19 +88,12 @@ module ActiveRecord
options.assert_valid_keys(VALID_FIND_OPTIONS)
- relation = relation.joins(options[:joins]).
- where(options[:conditions]).
- select(options[:select]).
- group(options[:group]).
- having(options[:having]).
- order(options[:order]).
- limit(options[:limit]).
- offset(options[:offset]).
- from(options[:from]).
- includes(options[:include])
-
- relation = relation.lock(options[:lock]) if options[:lock].present?
- relation = relation.readonly(options[:readonly]) if options.has_key?(:readonly)
+ [:joins, :select, :group, :having, :order, :limit, :offset, :from, :lock, :readonly].each do |finder|
+ relation = relation.send(finder, options[finder]) if options.has_key?(finder)
+ end
+
+ relation = relation.where(options[:conditions]) if options.has_key?(:conditions)
+ relation = relation.includes(options[:include]) if options.has_key?(:include)
relation
end