method
replace_on_target
v5.1.7 -
Show latest stable
- Class:
ActiveRecord::Associations::CollectionAssociation
replace_on_target(record, index, skip_callbacks)private
No documentation available.
# File activerecord/lib/active_record/associations/collection_association.rb, line 440
def replace_on_target(record, index, skip_callbacks)
callback(:before_add, record) unless skip_callbacks
set_inverse_instance(record)
@_was_loaded = true
yield(record) if block_given?
if index
target[index] = record
elsif @_was_loaded || !loaded?
target << record
end
callback(:after_add, record) unless skip_callbacks
record
ensure
@_was_loaded = nil
end