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/test/models | |
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/test/models')
-rw-r--r-- | activerecord/test/models/eye.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/activerecord/test/models/eye.rb b/activerecord/test/models/eye.rb new file mode 100644 index 0000000000..77f17b578e --- /dev/null +++ b/activerecord/test/models/eye.rb @@ -0,0 +1,37 @@ +class Eye < ActiveRecord::Base + attr_reader :after_create_callbacks_stack + attr_reader :after_update_callbacks_stack + attr_reader :after_save_callbacks_stack + + # Callbacks configured before the ones has_one sets up. + after_create :trace_after_create + after_update :trace_after_update + after_save :trace_after_save + + has_one :iris + accepts_nested_attributes_for :iris + + # Callbacks configured after the ones has_one sets up. + after_create :trace_after_create2 + after_update :trace_after_update2 + after_save :trace_after_save2 + + def trace_after_create + (@after_create_callbacks_stack ||= []) << iris.new_record? + end + alias trace_after_create2 trace_after_create + + def trace_after_update + (@after_update_callbacks_stack ||= []) << iris.changed? + end + alias trace_after_update2 trace_after_update + + def trace_after_save + (@after_save_callbacks_stack ||= []) << iris.changed? + end + alias trace_after_save2 trace_after_save +end + +class Iris < ActiveRecord::Base + belongs_to :eye +end |