Permalink
Browse files

removing spawn from SpawnMethods

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information...
1 parent 4745b53 commit aad432a9e91d991218276b5945d43e9dcb247b63 @tenderlove tenderlove committed with wycats Mar 10, 2010
@@ -26,7 +26,7 @@ def scoped(options = {}, &block)
if options.present?
Scope.init(self, options, &block)
else
- current_scoped_methods ? unscoped.merge(current_scoped_methods) : unscoped.spawn
+ current_scoped_methods ? unscoped.merge(current_scoped_methods) : unscoped.clone
end
end
@@ -21,6 +21,10 @@ def new(*args, &block)
with_create_scope { @klass.new(*args, &block) }
end
+ def initialize_copy(other)
+ reset
+ end
+
alias build new
def create(*args, &block)
@@ -8,7 +8,7 @@ module QueryMethods
class_eval <<-CEVAL
def #{query_method}(*args)
- new_relation = spawn
+ new_relation = clone
value = Array.wrap(args.flatten).reject {|x| x.blank? }
new_relation.#{query_method}_values += value if value.present?
new_relation
@@ -19,7 +19,7 @@ def #{query_method}(*args)
[:where, :having].each do |query_method|
class_eval <<-CEVAL
def #{query_method}(*args)
- new_relation = spawn
+ new_relation = clone
value = build_where(*args)
new_relation.#{query_method}_values += [*value] if value.present?
new_relation
@@ -32,7 +32,7 @@ def #{query_method}(*args)
class_eval <<-CEVAL
def #{query_method}(value = true)
- new_relation = spawn
+ new_relation = clone
new_relation.#{query_method}_value = value
new_relation
end
@@ -41,12 +41,12 @@ def #{query_method}(value = true)
end
def lock(locks = true)
- relation = spawn
+ relation = clone
case locks
when String, TrueClass, NilClass
- spawn.tap {|new_relation| new_relation.lock_value = locks || true }
+ clone.tap {|new_relation| new_relation.lock_value = locks || true }
else
- spawn.tap {|new_relation| new_relation.lock_value = false }
+ clone.tap {|new_relation| new_relation.lock_value = false }
end
end
@@ -1,11 +1,7 @@
module ActiveRecord
module SpawnMethods
- def spawn
- clone.reset
- end
-
def merge(r)
- merged_relation = spawn
+ merged_relation = clone
return merged_relation unless r
merged_relation = merged_relation.eager_load(r.eager_load_values).preload(r.preload_values).includes(r.includes_values)
@@ -83,7 +79,7 @@ def only(*onlies)
:order, :select, :readonly, :group, :having, :from, :lock ]
def apply_finder_options(options)
- relation = spawn
+ relation = clone
return relation unless options
options.assert_valid_keys(VALID_FIND_OPTIONS)

0 comments on commit aad432a

Please sign in to comment.