多个 after_commit 回调(Rails)的执行顺序 [英] Execution order of multiple after_commit callbacks (Rails)

查看:41
本文介绍了多个 after_commit 回调(Rails)的执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现在同一模型中定义的多个 after_commit 被以相反的顺序调用.例如

I recently found that multiple after_commits defined in the same model get called in reverse order. For example

after_commit method1, :on => :create
after_commit method2, :on => :create

method2method1 之前被调用.

它总是按 FILO 顺序调用吗?

Is it always called in FILO order?

推荐答案

此行为在 Rails 5.2.2.1 中仍然存在.

This behaviour is still present in Rails 5.2.2.1.

我的解决方案:

after_commit :after_commit_callbacks, :on => :create

def after_commit_callbacks
  method1
  method2
end

这篇关于多个 after_commit 回调(Rails)的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆