提交 9ebe33f1 编写于 作者: J Jeremy Kemper

r1601@asus: jeremy | 2005-07-02 14:33:08 -0700

 Only notify observers of after_find and after_initialize if these methods are defined on the model.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1620 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 d9d22c75
*SVN*
* Speed up ActiveRecord#method_missing for the common case (read_attribute).
* Only notify observers on after_find and after_initialize if these methods are defined on the model. [skaes@web.de]
* Fixed that single-table inheritance sub-classes couldn't be used to limit the result set with eager loading #1215 [Chris McGrath]
* Fixed validates_numericality_of to work with overrided getter-method when :allow_nil is on #1316 [raidel@onemail.at]
......
......@@ -213,32 +213,29 @@ def self.#{method}(*callbacks, &block)
module ClassMethods #:nodoc:
def instantiate_with_callbacks(record)
object = instantiate_without_callbacks(record)
if object.send(:respond_to_without_attributes?, :after_find)
if object.respond_to_without_attributes?(:after_find)
object.send(:callback, :after_find)
else
object.send(:invoke_and_notify, :after_find)
end
if object.send(:respond_to_without_attributes?, :after_initialize)
if object.respond_to_without_attributes?(:after_initialize)
object.send(:callback, :after_initialize)
else
object.send(:invoke_and_notify, :after_initialize)
end
object
end
end
# Is called when the object was instantiated by one of the finders, like Base.find.
# def after_find() end
#def after_find() end
# Is called after the object has been instantiated by a call to Base.new.
# def after_initialize() end
#def after_initialize() end
def initialize_with_callbacks(attributes = nil) #:nodoc:
initialize_without_callbacks(attributes)
result = yield self if block_given?
respond_to_without_attributes?(:after_initialize) ? callback(:after_initialize) : invoke_and_notify(:after_initialize)
callback(:after_initialize) if respond_to_without_attributes?(:after_initialize)
result
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册