Rails 原来 after_commit 和 after_save 有这样的区别

greatghoul · March 30, 2016 · Last by pynix replied at July 13, 2018 · 4546 hits

看了一篇文章 Five More Active Record Features You Should Be Using

里面讲到了 after_commit 和 after_save 的区别,如果 save 操作是在一个 transaction 中进行的,即使 transaction 失败回滚,after_save 依然会触发,但 after_commit 不会,印象中以前在 after_save 里面干了不少和非 ActiveRecord 对象交互的事儿,像发邮件呀什么的。

我也犯过同样的错····

难道不是正常逻辑?

You need to Sign in before reply, if you don't have an account, please Sign up first.