例子:

BillingProfile.transaction do
  if @billing_profile.save
    unless SomeService.do_something # returns false and rollback occurs
      raise ActiveRecord::Rollback
    end
  end
end

@billing_profile.persisted? # Still return true, despite rollback
@billing_profile.id # Is set, despite rollback

为什么@billing_profile 的状态不会反射(reflect)记录已回滚?

这是一个问题,因为记录回滚后无法创建。

最佳答案

原来这是 ActiveRecord (Rails 4) 中的一个错误:https://github.com/rails/rails/issues/13744

现在已经修复。

关于ruby-on-rails - 为什么坚持?在 ActiveRecord::Rollback 之后返回 true?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21175788/

10-10 15:23