method
configure_dependency_for_has_many

v1.2.6 -
Show latest stable
-
0 notes -
Class: ActiveRecord::Associations::ClassMethods
- 1.0.0
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (6)
- 2.1.0 (0)
- 2.2.1 (15)
- 2.3.8 (0)
- 3.0.0 (18)
- 3.0.9 (-1)
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
configure_dependency_for_has_many(reflection)
private
Hide source
# File activerecord/lib/active_record/associations.rb, line 1055 def configure_dependency_for_has_many(reflection) if reflection.options[:dependent] == true ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0. Please use :dependent => :destroy instead. See http://www.rubyonrails.org/deprecation for details.", caller) end if reflection.options[:dependent] && reflection.options[:exclusively_dependent] raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options. You may specify one or the other.' end if reflection.options[:exclusively_dependent] reflection.options[:dependent] = :delete_all ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0. Please use :dependent => :delete_all instead. See http://www.rubyonrails.org/deprecation for details.", caller) end # See HasManyAssociation#delete_records. Dependent associations # delete children, otherwise foreign key is set to NULL. # Add polymorphic type if the :as option is present dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id}) if reflection.options[:as] dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'" end case reflection.options[:dependent] when :destroy, true module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'" when :delete_all module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }" when :nullify module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL), %(#{dependent_conditions})) }" when nil, false # pass else raise ArgumentError, 'The :dependent option expects either :destroy, :delete_all, or :nullify' end end