aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/content.rb
blob: f2913be22df13e2b109b2ba418ace3aea75f1bea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true
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