dependent => destroy on a “has_many through” association

前端 未结 3 1911
攒了一身酷
攒了一身酷 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:24

    The original poster's solution is valid, however I wanted to point out that this only works if you have an id column for that table. I prefer my many-to-many tables to only be the two foreign keys, but I had to remove my "id: false" from the migration table definition for cascading delete to work. Having this functionality definitely outweighs not having an id column on the table.

提交回复
热议问题