显然,在使用:through选项时,dependent => destroy被忽略了。
所以我有这个...
class Comment < ActiveRecord::Base
has_many :comment_users, :dependent => :destroy
has_many :users, :through => :comment_users
...
end
然而删除评论并不会导致相关的comment_user记录被删除。
那么,在使用:through时,推荐的级联删除方法是什么呢?
谢谢
dependent: :destroy
也仍然出现了外键错误。问题在于我使用了obj.delete
而不是obj.destroy
,因此依赖项没有被删除,从而导致完整性错误。 - Tim Fletcher