Module: Tenacity::Associations::HasOne

Included in:
Tenacity
Defined in:
lib/tenacity/associations/has_one.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_t_cleanup_has_one_association(association) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tenacity/associations/has_one.rb', line 5

def _t_cleanup_has_one_association(association)
  associate = has_one_associate(association)
  unless associate.nil?
    if association.dependent == :destroy
      delete_or_destroy_has_one_associate(association, associate)
    elsif association.dependent == :delete
      delete_or_destroy_has_one_associate(association, associate, false)
    elsif association.dependent == :nullify
      nullify_foreign_key_for_has_one_associate(association, associate)
    elsif association.foreign_key_constraints_enabled?
      raise ObjectIdInUseError.new("Unable to delete #{self.class} with id of #{self.id} because its id is being referenced by an instance of #{associate.class}(id: #{associate.id})!")
    end
  end
end