新手问题 如何 create 使得 after_save 回调不执行

lehug · April 20, 2016 · Last by lehug replied at October 30, 2017 · 1755 hits

环境是 rails+mongodb。现在有一个关联表,初始化的时候,调用的是 find_or_create_by,并且 model 中定义了 after_save 为了数据修改后执行一个函数,结果初始化 find_or_create_by 的时候就会调用 after_save 使得运行很慢,如何操作可以让初始化 create 的时候不执行 after_save?

after_update

Rails 5 的话,可以用 suppress

#1 楼 @kikyous 谢谢,确实,我应该用 after_update,然后初始化 create 后再定义一个方法执行一次 update,谢谢

lehug closed this topic. 30 Oct 09:01
You need to Sign in before reply, if you don't have an account, please Sign up first.