aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-06-27 16:15:34 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-06-27 16:15:34 -0700
commit06d4247f0272109d6d3f1ff6beeaf6927f9b3c29 (patch)
treed8a2581570ffdd67bc95118f9e5c5c7d29e8fb95 /activerecord
parent5ddb60f2b35e67b500efbc2da0c752a64e36385b (diff)
downloadrails-06d4247f0272109d6d3f1ff6beeaf6927f9b3c29.tar.gz
rails-06d4247f0272109d6d3f1ff6beeaf6927f9b3c29.tar.bz2
rails-06d4247f0272109d6d3f1ff6beeaf6927f9b3c29.zip
AR object instantiation is ~30% faster in the simple case
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/base.rb2
-rw-r--r--activerecord/lib/active_record/named_scope.rb16
2 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 6106b03ba3..637e419735 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2074,7 +2074,7 @@ MSG
end
def populate_with_current_scope_attributes
- self.class.scoped.scope_for_create.each do |att,value|
+ self.class.scope_attributes.each do |att,value|
respond_to?("#{att}=") && send("#{att}=", value)
end
end
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 14db7a6cd6..f9299434ec 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -40,6 +40,22 @@ module ActiveRecord
end
end
+ ##
+ # Collects attributes from scopes that should be applied when creating
+ # an AR instance for the particular class this is called on.
+ def scope_attributes # :nodoc:
+ if current_scope
+ current_scope.scope_for_create
+ else
+ # Return an empty hash in the simple case
+ return {} unless finder_needs_type_condition? || default_scopes.any?
+
+ scope = relation.clone
+ scope.default_scoped = true
+ scope.scope_for_create
+ end
+ end
+
# Adds a class method for retrieving and querying objects. A \scope represents a narrowing of a database query,
# such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>.
#