Method: ReactiveRecord::Collection#update_child
- Defined in:
- lib/reactive_record/active_record/reactive_record/collection.rb
#update_child(item) ⇒ Object
appointment.doctor = doctor_value (i.e. through association is changing) means appointment.doctor_value.patients << appointment.patient and we have to appointment.doctor(current value).patients.delete(appointment.patient)
390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/reactive_record/active_record/reactive_record/collection.rb', line 390 def update_child(item) backing_record = item.backing_record if backing_record && @owner && @association && !@association.through_association? && item.attributes[@association.inverse_of] != @owner inverse_of = @association.inverse_of current_association = item.attributes[inverse_of] backing_record.virgin = false unless backing_record.data_loading? backing_record.update_belongs_to(inverse_of, @owner) if current_association && current_association.attributes[@association.attribute] current_association.attributes[@association.attribute].delete(item) end @owner.backing_record.sync_has_many(@association.attribute) end end |