提交 06d4247f 编写于 作者: A Aaron Patterson

AR object instantiation is ~30% faster in the simple case

上级 5ddb60f2
......@@ -2074,7 +2074,7 @@ def convert_number_column_value(value)
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
......
......@@ -40,6 +40,22 @@ def scoped(options = nil)
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>.
#
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册