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/schema/schema.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test/schema') diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 21b23d8e0c..477afe6feb 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -216,6 +216,14 @@ ActiveRecord::Schema.define do add_index :companies, [:firm_id, :type], name: "company_partial_index", where: "rating > 10" add_index :companies, :name, name: 'company_name_index', using: :btree + create_table :content, force: true do |t| + t.string :title + end + + create_table :content_positions, force: true do |t| + t.integer :content_id + end + create_table :vegetables, force: true do |t| t.string :name t.integer :seller_id -- cgit v1.2.3