title: Raising ActiveRecord::Rollback and loosing nested attribute values as a result
body: <p>In general I am trying to batch validate a bunch of objects and I need to save them to execute the uniqueness validations. Then I am rolling back the objects that needed to be saved for the uniqueness validation. </p>
  
  <p>This is needed for a batch importing UI where I want to notify users about problems in their data before they have the option to persist the data.</p>
  
  <p>The approach seems to fail because the object is losing its nested attributes when it is saved for the second time. So when saving the object a second time, MySQL/SQlite will rightfully tell me about the column being null.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>ActiveRecord::Schema.define do
    create_table :posts, force: true do |t|
      t.string :title
    end
  
    create_table :comments, force: true do |t|
      t.text :body, null: false
      t.integer :post_id
    end
  end
  
  class Post &lt; ActiveRecord::Base
    has_many :comments
    validates :title, uniqueness: true
    accepts_nested_attributes_for :comments
  end
  
  class Comment &lt; ActiveRecord::Base
    belongs_to :post
  end
  
  posts = [Post.new(title: "Title", comments_attributes: [{ body: "Comment" }])]
  
  ActiveRecord::Base.transaction do
    posts.each do |p|
      p.save # This saves fine
      # Collecting validation errors here for presentation purposes
    end
    raise ActiveRecord::Rollback
  end
  
  # Now the comment attributes seem to be gone and
  # Mysql is raising an error because the 'body' column is null
  posts.each { |p| p.save }
  </code></pre>
  
  <p>I have a fully runnable testcase here: <a href="https://gist.github.com/phansch/ab172e4b8cadf24f1e6508a0555e465c" rel="nofollow noreferrer">https://gist.github.com/phansch/ab172e4b8cadf24f1e6508a0555e465c</a></p>
  
  <p>Is there some way around this? I guess my problem boils down to having to execute the uniqueness validations to tell the user about duplicates before the user decides to go ahead and really persist the changes.</p>