app/forms/waste_carriers_engine/main_people_form.rb
def list_of_people_to_keep
      people = []

      # If there's only one main person allowed, we want to discard any existing main people, but keep people with
      # relevant convictions. Otherwise, we copy all the key_people, regardless of type.
      existing_people = if can_only_have_one_main_person?
                          transient_registration.relevant_people
                        else
                          transient_registration.key_people
                        end

      existing_people.each do |person|
        # We need to copy the person before adding to the array to avoid 'conflicting modifications' Mongo error (10151)
        people << person.clone
      end

      people
    end
# Adding the new main person directly to @transient_registration.key_people immediately updates the object,
# regardless of validation. So instead we copy all existing people into a new array and modify that.
Adding the new main person directly to @transient_registration.key_people immediately updates the object,
regardless of validation. So instead we copy all existing people into a new array and modify that.
Adding the new main person directly to @transient_registration . key_people immediately updates the object regardless of validation . So instead we copy all existing people into a new array and modify that .
def list_of_people_to_keep
      people = []
      existing_people = if can_only_have_one_main_person?
                          transient_registration.relevant_people
                        else
                          transient_registration.key_people
                        end
      existing_people.each do |person|
        people << person.clone
      end
      people
    end
def list_of_people_to_keep people = [ ] existing_people = if can_only_have_one_main_person? transient_registration . relevant_people else transient_registration . key_people end existing_people . each do | person | people << person . clone end people end
Adding the new main person directly to @transient_registration.key_people immediately updates the object,
regardless of validation.
Adding the new main person directly to @transient_registration . key_people immediately updates the object regardless of validation .
# If there's only one main person allowed, we want to discard any existing main people, but keep people with # relevant convictions. Otherwise, we copy all the key_people, regardless of type. # We need to copy the person before adding to the array to avoid 'conflicting modifications' Mongo error (10151)