aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-14 00:04:14 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-14 00:04:14 +0000
commit7edb10fe682d5fa9802b2b5355b1073444042fc4 (patch)
tree45c6c8afac5c8720ad50bc141fe2f9e7cd6359bc /activerecord/lib
parent0f4ee4b810728fa5fd32cfe14501fc3d8eaf6051 (diff)
downloadrails-7edb10fe682d5fa9802b2b5355b1073444042fc4.tar.gz
rails-7edb10fe682d5fa9802b2b5355b1073444042fc4.tar.bz2
rails-7edb10fe682d5fa9802b2b5355b1073444042fc4.zip
Added that all types of after_find/after_initialized callbacks are triggered if the explicit implementation is present, not only the explicit implementation itself
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@898 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/callbacks.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index 2e0bfd3e03..f92e38a0d0 100755
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -151,8 +151,8 @@ module ActiveRecord
#
# Because after_find and after_initialize is called for each object instantiated found by a finder, such as Base.find_all, we've had
# to implement a simple performance constraint (50% more speed on a simple test case). Unlike all the other callbacks, after_find and
- # after_initialize can only be declared using an explicit implementation. So using the inheritable callback queue for after_find and
- # after_initialize won't work.
+ # after_initialize will only be run if an explicit implementation is defined (<tt>def after_find</tt>). In that case, all of the
+ # callback types will be called.
#
# == Cancelling callbacks
#
@@ -209,8 +209,19 @@ module ActiveRecord
module ClassMethods #:nodoc:
def instantiate_with_callbacks(record)
object = instantiate_without_callbacks(record)
- object.send(:invoke_and_notify, :after_find)
- object.send(:invoke_and_notify, :after_initialize)
+
+ if object.send(: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)
+ object.send(:callback, :after_initialize)
+ else
+ object.send(:invoke_and_notify, :after_initialize)
+ end
+
object
end
end
@@ -223,7 +234,7 @@ module ActiveRecord
def initialize_with_callbacks(attributes = nil) #:nodoc:
initialize_without_callbacks(attributes)
result = yield self if block_given?
- invoke_and_notify(:after_initialize)
+ respond_to_without_attributes?(:after_initialize) ? callback(:after_initialize) : invoke_and_notify(:after_initialize)
result
end