例如
User
references_many :answers
Answer
references_many :users
假设我们正在删除给定用户的答案,我们该怎么做才能删除用户/答案对象上的两个引用?
答案 0 :(得分:2)
级联删除
与ActiveRecord类似,如果您希望在删除父记录时删除子关系关联,只需在references_one或references_many宏上提供:dependent选项。
class User
include Mongoid::Document
references_one :profile, :dependent => :destroy
references_many :answers, :dependent => :delete
end