dependent => destroy on a “has_many through” association

前端 未结 3 1920
攒了一身酷
攒了一身酷 2020-12-08 01:56

Apparently dependent => destroy is ignored when also using the :through option.

So I have this...

class Comment < ActiveRecord::Base
  has_many :c         


        
3条回答
  •  渐次进展
    2020-12-08 02:48

    If you have a polymorphic association, you should do what @blogofsongs said but with a foreign_key attribute like so:

    class User < ActiveRecord::Base
      has_many :activities , dependent: :destroy, foreign_key: :trackable_id
    end
    

提交回复
热议问题