如何跳过 ActiveRecord 回调? [英] How to skip ActiveRecord callbacks?
本文介绍了如何跳过 ActiveRecord 回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何避免运行 ActiveRecord 回调?
我有这样的模型
class Vote < ActiveRecord::Base
after_save :add_points_to_user
.....
end
是否可以以某种方式强制模型在保存时跳过调用 add_points_to_user
?可能类似于 ActiveRecord#delete
与 ActiveRecord#destroy
?
Is it possible to somehow force model to skip calling add_points_to_user
when saved? Possibly something like ActiveRecord#delete
vs ActiveRecord#destroy
?
推荐答案
对于 Rails 2,但不是 Rails 3,您可以使用这些:
For Rails 2, but not Rails 3 you can use these:
object.send(:create_without_callbacks)
object.send(:update_without_callbacks)
这篇关于如何跳过 ActiveRecord 回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文