class ActiveRecord::Associations::CollectionAssociation

Private Instance Methods

replace_records(new_target, original_target) click to toggle source
# File lib/replace_with_destroy.rb, line 10
def replace_records(new_target, original_target)
  if ReplaceWithDestroy::ALL || self.options[:replace_with_destroy]
    destroy(target - new_target)
  else
    delete(target - new_target)
  end

  unless concat(new_target - target)
    @target = original_target
    raise RecordNotSaved, "Failed to replace #{reflection.name} because one or more of the " \
                          "new records could not be saved."
  end

  target
end