krishna krishna - 29 days ago 11
Ruby Question

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?

Answer

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

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

Comments