From 5b86c3e5bb2bb54003d8f211b46a7b992355dbf5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 22 Oct 2010 10:28:53 +0200 Subject: has_one maintains the association with separate after_create/after_update This way parent models can get their own after_create and after_update callbacks fired after has_one has done its job. --- activerecord/lib/active_record/autosave_association.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/autosave_association.rb') diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 21a9a1f2cb..4a2c078e91 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -167,7 +167,16 @@ module ActiveRecord else if reflection.macro == :has_one define_method(save_method) { save_has_one_association(reflection) } - after_save save_method + # Configures two callbacks instead of a single after_save so that + # the model may rely on their execution order relative to its + # own callbacks. + # + # For example, given that after_creates run before after_saves, if + # we configured instead an after_save there would be no way to fire + # a custom after_create callback after the child association gets + # created. + after_create save_method + after_update save_method else define_method(save_method) { save_belongs_to_association(reflection) } before_save save_method -- cgit v1.2.3