rails/rails — Issue #3992: has_many through transaction rollback failed
Author: imustardsoft
Created: 2011-12-15 09:05:24+00:00
State: open

I have bellow one model has many other model.

The question is when i update 2 models. One model is validate failed. The other model can not rollback.

Sample:

class User < ActiveRecord::Base
has_many :products, :dependent => :destroy
validates_presence_of :name
end

class Product < ActiveRecord::Base
belongs_to :user
end

# do a update

User.transaction do
user = User.find(1)
p user.products # => [#product1,#product2]
user.products = [#product3, #product4]
user.name = ""
user.save
end

=>
validate error: Name can't be blank

But when you run bellow.
user = User.find(1)
p user.products # => [#product3,#product4]

How can i resolve this problem?
I don't need products are updated as the user is validate failure

I use
.mysql innoDB
.Rails 3.0.3
.activerecord (3.0.3)