Hello, I've checked the bug:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6566-accepts_nested_attributes_for-not-updating-correctly-with-validates_uniqueness_of#ticket-6566-7

And noticed that since the validations are checked before executing
the SQL updates it will always fail even if it is within a
transaction. I though perhaps it could be interesting to delay
validations at the end of the transactional context.

I would like to know if you are interested in adding such a type of
functionality.
TIA

Example to add to test/cases/validations/uniqueness_validation_test.rb

def test_validate_uniqueness_when_swapping_values_within_transaction
    Event.new( title:'E1').save!
    Event.new( title:'E2').save!
    ActiveRecord::Base.transaction do
      e1 = Event.find(1)
      e2 = Event.find(2)
      e1.title = 'E2'
      e2.title = 'E1'
      e2.save
      e1.save
    end
    assert_equal Event.find(1).title, 'E2'
    assert_equal Event.find(2).title, 'E1'
  end

An equivalent SQL would be:

Begin
update events set title='E2' where id = 1;
update events set title='E1' where id = 2;

Check Constraints after updates:
select events.id from events where title = 'E2' and id <> 1;
select events.id from events where title = 'E1' and id <> 2;
Commit or Rollback accordingly

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to