method
configure_dependency_for_belongs_to
v2.3.8 -
Show latest stable
- Class:
ActiveRecord::Associations::ClassMethods
configure_dependency_for_belongs_to(reflection)private
No documentation available.
# File activerecord/lib/active_record/associations.rb, line 1494
def configure_dependency_for_belongs_to(reflection)
if reflection.options.include?(:dependent)
case reflection.options[:dependent]
when :destroy
method_name = "belongs_to_dependent_destroy_for_#{reflection.name}".to_sym
define_method(method_name) do
association = send(reflection.name)
association.destroy unless association.nil?
end
after_destroy method_name
when :delete
method_name = "belongs_to_dependent_delete_for_#{reflection.name}".to_sym
define_method(method_name) do
association = send(reflection.name)
association.delete unless association.nil?
end
after_destroy method_name
else
raise ArgumentError, "The :dependent option expects either :destroy or :delete (#{reflection.options[:dependent].inspect})"
end
end
end