diff options
author | Xavier Noria <fxn@hashref.com> | 2010-10-22 10:28:53 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-10-22 10:28:53 +0200 |
commit | 5b86c3e5bb2bb54003d8f211b46a7b992355dbf5 (patch) | |
tree | 1375ec5b4b1bfc68b8255b82980aa6bb45b6da3b /activerecord/lib | |
parent | fc8c0729881fff59e916f7ab180dbfa03ee1b891 (diff) | |
download | rails-5b86c3e5bb2bb54003d8f211b46a7b992355dbf5.tar.gz rails-5b86c3e5bb2bb54003d8f211b46a7b992355dbf5.tar.bz2 rails-5b86c3e5bb2bb54003d8f211b46a7b992355dbf5.zip |
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.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 11 |
1 files changed, 10 insertions, 1 deletions
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 |