「destroy_allはdependent: :destroyを無視する」と記憶していたのですが、そうでもないよ、というはなし。
ActiveRecord::Associations::CollectionProxy
Deletes the records of the collection directly from the database ignoring the :dependent option.
foo.bars.destroy_all
無視するのはこっちだけで、
Each object’s callbacks are executed (including :dependent association options).
Bar.where(foo_id: foo.id).destroy_all
こっちは無視しない。うっかりしちゃうなぁ。

コメント