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

greatghoul · 2016年03月30日 · 最后由 pynix 回复于 2018年07月13日 · 4545 次阅读

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

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

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

难道不是正常逻辑?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号