method
handle_dependency
v5.0.0.1 -
Show latest stable
- Class:
ActiveRecord::Associations::HasManyAssociation
handle_dependency()public
No documentation available.
# File activerecord/lib/active_record/associations/has_many_association.rb, line 11
def handle_dependency
case options[:dependent]
when :restrict_with_exception
raise ActiveRecord::DeleteRestrictionError.new(reflection.name) unless empty?
when :restrict_with_error
unless empty?
record = owner.class.human_attribute_name(reflection.name).downcase
message = owner.errors.generate_message(:base, :'restrict_dependent_destroy.many', record: record, raise: true) rescue nil
if message
ActiveSupport::Deprecation.warn( The error key `:'restrict_dependent_destroy.many'` has been deprecated and will be removed in Rails 5.1. Please use `:'restrict_dependent_destroy.has_many'` instead..squish)
end
owner.errors.add(:base, message || :'restrict_dependent_destroy.has_many', record: record)
throw(:abort)
end
else
if options[:dependent] == :destroy
# No point in executing the counter update since we're going to destroy the parent anyway
load_target.each { |t| t.destroyed_by_association = reflection }
destroy_all
else
delete_all
end
end
end