rails/rails — pull request #9717 by pftg (2013-03-14 11:48:52+00:00)
Title:  #7347: Destroy marked child records before new child records inserted

This pull request should resolve #7347 issue.

There was a bug/annoying problem when:

1. there are some child records for has many association marked for destruction,
1. in the the same transaction added new child records which conflicts with marked records by schema constraints like unique values for some attributes,
1. on save there is Rollback Exception, because new conflicted records have been inserted before marked for destruction records are destroyed.

Example code: https://gist.github.com/pftg/5160669