title: Deleting old records assigned to variable
body: <p>My main goal is to remove old records after new records are correctly created. I tried assigning it to variable and using <code>#dup</code> method. Please look at the example code:</p>
  
  <pre><code>def my_method
    old_items = @user.items.dup
  
    new_items = @user.items.new(item_params) # one or more
  
    # confusing part
    old_items.destroy_all if new_items.save
  end
  </code></pre>
  
  <p>I wanted to destroy <code>old_items</code> but when I created new_items they were <code>old_items == new_items</code>. Why duplication <code>#dup</code> was not working here? How could I split and remove old records? I also tried a transaction (rollback if new_items are invalid), which also did not work. </p>