From 9ebe33f14b10fc00b227a408b846b6d2329746b8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 3 Jul 2005 08:27:18 +0000 Subject: 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 --- activerecord/CHANGELOG | 4 ++++ activerecord/lib/active_record/callbacks.rb | 19 ++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index ebf3d3b244..25addad806 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,9 @@ *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] diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 8e95502e56..629272b639 100755 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -213,32 +213,29 @@ module ActiveRecord 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 -- cgit v1.2.3