为什么在子块中出现异常后 ActiveRecord 不回滚嵌套事务中的更改?
以下是示例:
1.
>> Client.transaction do
?> Client.create(:name => 'Pavel')
>> Client.transaction do
?> Client.create(:name => 'Elena')
>> raise ActiveRecord::Rollback
>> end
>> end
=> nil
>> Client.all.map(&:name)
=> ["Pavel", "Elena"] # instead of []
2.
>> Client.transaction do
?> Client.create(:name => 'Pavel')
>> Client.transaction(:requires_new => true) do
?> Client.create(:name => 'Elena')
>> raise ActiveRecord::Rollback
>> end
>> end
=> nil
>> Client.all.map(&:name)
=> ["Pavel", "Elena"] # instead of ["Pavel"]
谢谢。
Debian GNU/Linux 5.0.6;
红宝石 1.9.2;
Ruby on Rails 3.0.1;
SQLite 3.7.3。