Class: ActiveRecord::Associations::HasManyAssociation
- Inherits:
-
CollectionAssociation
- Object
- Association
- CollectionAssociation
- ActiveRecord::Associations::HasManyAssociation
- Includes:
- ForeignAssociation
- Defined in:
- lib/active_record/associations/has_many_association.rb
Overview
Active Record Has Many Association
This is the proxy that handles a has many association.
If the association has a :through
option further specialization is provided by its child HasManyThroughAssociation.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Association
Instance Method Summary collapse
Methods included from ForeignAssociation
#foreign_key_present?, #nullified_owner_attributes
Methods inherited from CollectionAssociation
#add_to_target, #build, #concat, #delete, #delete_all, #destroy, #destroy_all, #empty?, #find, #find_from_target?, #ids_reader, #ids_writer, #include?, #load_target, #null_scope?, #reader, #replace, #reset, #scope, #size, #transaction, #writer
Methods inherited from Association
#create, #create!, #extensions, #initialize, #initialize_attributes, #inversed_from, #klass, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #remove_inverse_instance, #reset, #reset_scope, #scope, #set_inverse_instance, #set_inverse_instance_from_queries, #stale_target?
Constructor Details
This class inherits a constructor from ActiveRecord::Associations::Association
Instance Method Details
#handle_dependency ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_record/associations/has_many_association.rb', line 13 def handle_dependency case [: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 owner.errors.add(:base, :'restrict_dependent_destroy.has_many', record: record) throw(:abort) end when :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 |
#insert_record(record, validate = true, raise = false) ⇒ Object
34 35 36 37 |
# File 'lib/active_record/associations/has_many_association.rb', line 34 def insert_record(record, validate = true, raise = false) set_owner_attributes(record) super end |