dependent destroy not working

后端 未结 2 2017
礼貌的吻别
礼貌的吻别 2021-02-13 21:18

I\'m trying to use dependent: :destroy without success.

Lets put a simple example. I create a simple application with the following:

rails g model parent         


        
2条回答
  •  [愿得一人]
    2021-02-13 21:54

    Calling the delete method on an ActiveRecord derived object will issue a direct DELETE statement do the database, skipping any ActiveRecord callbacks and configurations such as dependent: destroy.

    I believe you want the destroy method.

    You could also set up a foreign key in the database and set it to cascade on delete, it might make sense, depending on your needs.

提交回复
热议问题