顯然依賴=>在使用:through選項時忽略destroy。dependent =>通過「has_many through」關聯銷燬
所以我有這個...
class Comment < ActiveRecord::Base
has_many :comment_users, :dependent => :destroy
has_many :users, :through => :comment_users
...
end
...但刪除評論不會導致相關comment_user記錄越來越刪除。
什麼是推薦的方法,然後,級聯刪除時使用:通過?
謝謝
的確!我有一個類似的問題,除了我在使用'dependent::destroy'的時候出現外鍵錯誤。問題是我使用'obj.delete'而不是'obj.destroy',所以依賴者沒有被刪除,因此完整性錯誤。 – 2017-11-07 18:02:36