Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails dependent destroy and really destroy an acts_aS_paranoid object

I have two models articles and bookmarks. Both are defined as acts_as_paranoid objects. Relationship between them is

article.rb

  has_many :bookmarks, foreign_key: 'article_doi', primary_key: 'doi', dependent: :destroy

bookmark.rb

  belongs_to :article, foreign_key: 'article_doi', primary_key: 'doi'

Now I want to really remove a bookmark object and also remove the dependent bookmarks objects.

@article.destroy!

and checked

@article.bookmarks

did not remove the article or its bookmarks. How can I really remove them from the database and its associated bookmarks?

like image 943
krishna Avatar asked Feb 05 '23 18:02

krishna


1 Answers

To permanently destroy from database you can use really_destroy! method. Try using @article.really_destroy!

https://github.com/rubysherpas/paranoia#usage

like image 140
Gokul Avatar answered Feb 16 '23 00:02

Gokul