大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 用ActiveRecord冒泡嵌套事务失败,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
class PostCreator def create ActiveRecord::Base.transaction do post.do_this post.do_that user.do_more(post,other_stuff) end end end def Post def do_this transaction do; ...; end end end
我需要任何嵌套的失败来一直到顶部,但我不知道如何发生这种情况,而在nested transactions的ActiveRecord文档似乎没有提供一个解决方案.从文档:
# Standard nesTing User.transaction do User.create(username: 'Kotori') User.transaction do User.create(username: 'Nemu') raise ActiveRecord::rollBACk # This won't bubble up: # _Both_ users will still be created. end end # nesTing with `requires_new: true` on the nested transaction User.transaction do User.create(username: 'Kotori') User.transaction(requires_new: truE) do User.create(username: 'Nemu') raise ActiveRecord::rollBACk # This won't bubble up either # "Kotori" will still be created. end end
以上是大佬教程为你收集整理的ruby-on-rails – 用ActiveRecord冒泡嵌套事务失败全部内容,希望文章能够帮你解决ruby-on-rails – 用ActiveRecord冒泡嵌套事务失败所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。