Ruby on rails Mongoid嵌入文档以自动保存(触发回调)父级

Ruby on rails Mongoid嵌入文档以自动保存(触发回调)父级,ruby-on-rails,ruby,mongodb,mongoid,Ruby On Rails,Ruby,Mongodb,Mongoid,如果我有以下课程: class Bar include Mongoid::Document embeds_many :foos, :cascade_callbacks => true end class Foo include Mongoid::Document embedded_in :bar, :inverse_of => :foos end 有没有可能在保存/更新Foo时自动保存它的父栏(特别是调用它自己的“before_save”回调)。 我想这样做,而不

如果我有以下课程:

class Bar
  include Mongoid::Document
  embeds_many :foos, :cascade_callbacks => true
end

class Foo
  include Mongoid::Document
  embedded_in :bar, :inverse_of => :foos
end
有没有可能在保存/更新Foo时自动保存它的父栏(特别是调用它自己的“before_save”回调)。 我想这样做,而不必向Foo公开Bar的方法

即不作为解决方案执行此操作:

class Bar
  include Mongoid::Document
  embeds_many :foos, :cascade_callbacks => true

  def update_stuff_on_bar
   # Stuff
  end
end

class Foo
  include Mongoid::Document
  embedded_in :bar, :inverse_of => :foos
  before_save :update_parent

  def update_parent
    bar.update_stuff_on_bar # <- We're having to use internals of Bar inside Foo. 
  end
end
类栏
include Mongoid::Document
嵌入\u many:foos,:cascade\u回调=>true
def更新工具栏上的内容
#东西
结束
结束
福班
include Mongoid::Document
嵌入在:bar,:inverse\u of=>:foos中
保存前:更新父项
def更新\u父级
酒吧。更新酒吧里的东西#