2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-15 18:03:23 -05:00
|
|
|
class Content < ActiveRecord::Base
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "content"
|
2015-01-15 18:03:23 -05:00
|
|
|
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
|
2016-08-06 12:26:20 -04:00
|
|
|
self.table_name = "content"
|
|
|
|
has_one :content_position, foreign_key: "content_id", dependent: :destroy
|
2015-01-15 18:03:23 -05:00
|
|
|
|
|
|
|
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
|