似乎有一种方法可以跳过non-relation callbacks,但我尝试了以下内容,关系回调仍在被解雇:
class Foo
include Mongoid::Document
has_and_belongs_to_many :elements, after_add: :add_callback
field :name
after_update :do_update
def do_update
Foo.skip_callback(:save, :after, :add_callback)
self.elements << Element.create(name: "NEW ELEMENT")
Foo.set_callback(:save, :after, :add_callback)
end
def add_callback
Foo.skip_callback(:save, :after, :add_callback)
self.elements << Element.create(name: "ANOTHER NEW ELEMENT")
Foo.set_callback(:save, :after, :add_callback)
end
end
由于add_callback
被持续发起,因此skip_callback
似乎无效。
如何跳过关系回调?