diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-28 12:24:07 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-28 12:24:07 -0600 |
commit | f7d0a3ba7e9e676d399e7aeed7485a8bf03992f8 (patch) | |
tree | 2021a3477af697b70198a739082befd7780ff321 /activerecord/test/models | |
parent | d74c89ac16aa87f3bc166450e8d4b87382da17a4 (diff) | |
parent | d5bf649a535948e70692e521ce3070595334e71b (diff) | |
download | rails-f7d0a3ba7e9e676d399e7aeed7485a8bf03992f8.tar.gz rails-f7d0a3ba7e9e676d399e7aeed7485a8bf03992f8.tar.bz2 rails-f7d0a3ba7e9e676d399e7aeed7485a8bf03992f8.zip |
Merge pull request #18548 from sebjacobs/support-bidirectional-destroy-dependencies
Add support for bidirectional destroy dependencies
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/content.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/activerecord/test/models/content.rb b/activerecord/test/models/content.rb new file mode 100644 index 0000000000..140e1dfc78 --- /dev/null +++ b/activerecord/test/models/content.rb @@ -0,0 +1,40 @@ +class Content < ActiveRecord::Base + self.table_name = 'content' + has_one :content_position, dependent: :destroy + + def self.destroyed_ids + @destroyed_ids ||= [] + end + + before_destroy do |object| + Content.destroyed_ids << object.id + end +end + +class ContentWhichRequiresTwoDestroyCalls < ActiveRecord::Base + self.table_name = 'content' + has_one :content_position, foreign_key: 'content_id', dependent: :destroy + + after_initialize do + @destroy_count = 0 + end + + before_destroy do + @destroy_count += 1 + if @destroy_count == 1 + throw :abort + end + end +end + +class ContentPosition < ActiveRecord::Base + belongs_to :content, dependent: :destroy + + def self.destroyed_ids + @destroyed_ids ||= [] + end + + before_destroy do |object| + ContentPosition.destroyed_ids << object.id + end +end |