From d5bf649a535948e70692e521ce3070595334e71b Mon Sep 17 00:00:00 2001 From: Seb Jacobs Date: Thu, 15 Jan 2015 23:03:23 +0000 Subject: Add support for bidirectional destroy dependencies Prior to this commit if you defined a bidirectional relationship between two models with destroy dependencies on both sides, a call to `destroy` would result in an infinite callback loop. Take the following relationship. class Content < ActiveRecord::Base has_one :content_position, dependent: :destroy end class ContentPosition < ActiveRecord::Base belongs_to :content, dependent: :destroy end Calling `Content#destroy` or `ContentPosition#destroy` would result in an infinite callback loop. This commit changes the behaviour of `ActiveRecord::Callbacks#destroy` so that it guards against subsequent callbacks. Thanks to @zetter for demonstrating the issue with failing tests[1]. [1] rails#13609 --- activerecord/test/fixtures/content.yml | 3 +++ activerecord/test/fixtures/content_positions.yml | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 activerecord/test/fixtures/content.yml create mode 100644 activerecord/test/fixtures/content_positions.yml (limited to 'activerecord/test/fixtures') diff --git a/activerecord/test/fixtures/content.yml b/activerecord/test/fixtures/content.yml new file mode 100644 index 0000000000..0d12ee03dc --- /dev/null +++ b/activerecord/test/fixtures/content.yml @@ -0,0 +1,3 @@ +content: + id: 1 + title: How to use Rails diff --git a/activerecord/test/fixtures/content_positions.yml b/activerecord/test/fixtures/content_positions.yml new file mode 100644 index 0000000000..9e85773f8e --- /dev/null +++ b/activerecord/test/fixtures/content_positions.yml @@ -0,0 +1,3 @@ +content_positions: + id: 1 + content_id: 1 -- cgit v1.2.3