1
User
references_many :answers
Answer
references_many :users
說,我們正在刪除給定用戶的答案,我們該怎麼做就使得這兩個用戶/應答對象的引用被刪除?
User
references_many :answers
Answer
references_many :users
說,我們正在刪除給定用戶的答案,我們該怎麼做就使得這兩個用戶/應答對象的引用被刪除?
層疊減除
到的ActiveRecord類似,如果你要當父記錄被刪除到被刪除親子關係協會,只需提供:在references_one或references_many宏依賴選項。
class User
include Mongoid::Document
references_one :profile, :dependent => :destroy
references_many :answers, :dependent => :delete
end