aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-03-10 08:51:11 -0800
committerwycats <wycats@gmail.com>2010-03-10 13:29:00 -0800
commitaad432a9e91d991218276b5945d43e9dcb247b63 (patch)
tree8f3282265a10a1ddd37b64387af96b81d51c9408 /activerecord
parent4745b53bcda400cf2e8cb4f2c0bf068f6d13c0e5 (diff)
downloadrails-aad432a9e91d991218276b5945d43e9dcb247b63.tar.gz
rails-aad432a9e91d991218276b5945d43e9dcb247b63.tar.bz2
rails-aad432a9e91d991218276b5945d43e9dcb247b63.zip
removing spawn from SpawnMethods
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/named_scope.rb2
-rw-r--r--activerecord/lib/active_record/relation.rb4
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb12
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb8
4 files changed, 13 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index f1f56850ae..394e1587e1 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -26,7 +26,7 @@ module ActiveRecord
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
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 7bc3d3bf33..aca4629dd8 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -21,6 +21,10 @@ module ActiveRecord
with_create_scope { @klass.new(*args, &block) }
end
+ def initialize_copy(other)
+ reset
+ end
+
alias build new
def create(*args, &block)
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 6c4e84a958..e00d9cdf27 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -8,7 +8,7 @@ module ActiveRecord
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 @@ module ActiveRecord
[: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 @@ module ActiveRecord
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 @@ module ActiveRecord
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
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb
index cccf413e67..a18380f01c 100644
--- a/activerecord/lib/active_record/relation/spawn_methods.rb
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb
@@ -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 @@ module ActiveRecord
: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)