I know there are performance issues with this trickling down (and possibly other downsides too that I haven't thought of), still if would be nice if there was an option to have callbacks trickle down, similar to the :autosave flag on relations.
This code should do the trick:
module Mongoid #:nodoc:
module Associations #:nodoc:
module EmbeddedCallbacks
- bubble callbacks to embedded associations
def run_callbacks(kind, *args, &block) - now bubble callbacks down
self.relations.each_pair do |name, meta|
if meta.relation == Mongoid::Relations::Embedded::Many
self.send(name).each { |doc| doc.send(:run_callbacks, kind, *args, &block) }elsif meta.association == Mongoid::Relations::Embedded::One
self.send(name).send(:run_callbacks, kind, *args, &block)
end
end
super(kind, *args, &block) # defer to parent
end
end
end
end