Class: ActiveRecord::Associations::HasManyAssociation
- Inherits:
-
CollectionAssociation
- Object
- Association
- CollectionAssociation
- ActiveRecord::Associations::HasManyAssociation
- Defined in:
- lib/ocean-dynamo/active_record_stuff/has_many_association.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from Association
Instance Method Summary collapse
-
#handle_dependency ⇒ Object
:nodoc:.
- #insert_record(record, validate = true, raise = false) ⇒ Object
Methods inherited from CollectionAssociation
#add_to_target, #any?, #build, #concat, #count, #create, #create!, #delete, #delete_all, #destroy, #destroy_all, #distinct, #empty?, #find, #first, #ids_reader, #ids_writer, #include?, #last, #length, #load_target, #many?, #null_scope?, #reader, #replace, #reset, #scope, #select, #size, #transaction, #writer
Methods inherited from Association
#aliased_table_name, #association_scope, #initialize, #interpolate, #klass, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #reset, #reset_scope, #scope, #scoped, #set_inverse_instance, #stale_target?, #target_scope
Constructor Details
This class inherits a constructor from ActiveRecord::Associations::Association
Instance Method Details
#handle_dependency ⇒ Object
:nodoc:
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ocean-dynamo/active_record_stuff/has_many_association.rb', line 10 def handle_dependency case [:dependent] when :restrict_with_exception raise ActiveRecord::DeleteRestrictionError.new(reflection.name) unless empty? when :restrict_with_error unless empty? record = klass.human_attribute_name(reflection.name).downcase owner.errors.add(:base, :"restrict_dependent_destroy.many", record: record) false end else if [: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 |
#insert_record(record, validate = true, raise = false) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/ocean-dynamo/active_record_stuff/has_many_association.rb', line 33 def insert_record(record, validate = true, raise = false) set_owner_attributes(record) if raise record.save!(:validate => validate) else record.save(:validate => validate) end end |