提交 02f45d6e 编写于 作者: A Aaron Patterson

reduce object allocation during AR instantiation

上级 c290900a
......@@ -2082,6 +2082,8 @@ def convert_number_column_value(value)
end
def populate_with_current_scope_attributes
return unless self.class.scope_attributes?
self.class.scope_attributes.each do |att,value|
send("#{att}=", value) if respond_to?("#{att}=")
end
......
......@@ -47,15 +47,18 @@ def scope_attributes # :nodoc:
if current_scope
current_scope.scope_for_create
else
# Return an empty hash in the simple case
return {} unless default_scopes.any?
scope = relation.clone
scope.default_scoped = true
scope.scope_for_create
end
end
##
# Are there default attributes associated with this scope?
def scope_attributes? # :nodoc:
current_scope || default_scopes.any?
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.
先完成此消息的编辑!
想要评论请 注册