replace(other_array)
public
Replace this collection with other_array This will perform a diff
and delete/add only records that have changed.
# File activerecord/lib/active_record/associations/association_collection.rb, line 228
def replace(other_array)
other_array.each { |val| raise_on_type_mismatch(val) }
load_target
other = other_array.size < 100 ? other_array : other_array.to_set
current = @target.size < 100 ? @target : @target.to_set
@owner.transaction do
delete(@target.select { |v| !other.include?(v) })
concat(other_array.select { |v| !current.include?(v) })
end
end