Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jisaacks/recurse-delete
Rails gem to recursively delete self and all dependent associations without an N+1
https://github.com/jisaacks/recurse-delete
Last synced: 22 days ago
JSON representation
Rails gem to recursively delete self and all dependent associations without an N+1
- Host: GitHub
- URL: https://github.com/jisaacks/recurse-delete
- Owner: jisaacks
- Created: 2012-05-20T20:28:41.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-05-03T00:37:16.000Z (over 9 years ago)
- Last Synced: 2024-10-03T12:51:22.018Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 194 KB
- Stars: 25
- Watchers: 3
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
##Recurse Delete
When you call Record.destroy in Rails, it instantiates all its associations (that are :dependent => :destroy) and calls destroy on each. This is an N + 1, you can delete all the associated records without the N + 1 if you set the association as :dependent => :delete_all. However, this will not delete all the sub associations. This is the compromise recurse-delete solves. You can read more about it here: http://programming-perils.com/436/rails-prevent-dependent-destroy-n-plus-ones/
Add to GemFile: **gem 'recurse-delete'**
Usage: `Record.recurse_delete`