Support for destroy() to DELETE ALL entities of the given model
See original GitHub issueCurrently (v. 0.9.2), the documentation on model.destroy()
says:
destroy
performs adelete
on the model, using the model’sidAttribute
to constrain the query.
Without a constraining idAttribute
, destroy()
fails with the error message
A model cannot be destroyed without a "where" clause or an idAttribute.
However, it would be desirable to be able to actually do a
DELETE FROM MY_MODEL
…deleting all entities of the given model.
Yes, it’s a dangerous operation, but a useful one for cleanup / prototyping purposes. If you really want to keep an additional security net in the API, please consider adding a flag to destroy()
to override the “idAttribute constraint” such that we can purposefully do a “delete all”.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Sequelize: Destroy/Delete all records in the table
When testing begins, I would like to delete all the previous records in a table. What I have tried: db.User.destroy({ force: true }).then(()...
Read more >[SOLVED] What is the best way to destroy an Entity from the ...
I'm trying to delete some cubes on a game after pressing a button. ... That is strange, entity.destroy() would definitely remove all entity...
Read more >Deleting items in Rails
In this article, we are going to see the different methods to delete items in Rails. It's quite easy to confuse between destroy,...
Read more >How to Delete Multiple Records Using Laravel Eloquent
I want to be able to delete multiple records from the database. I have the id 's of all the records I wish...
Read more >Deleting Data - 4.x - CakePHP Cookbook
deleteAll will not trigger beforeDelete/afterDelete events. If you need callbacks triggered, first load the entities with find() and delete them in a loop....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK, so I found a workaround. The obvious solution is to use a
where()
clause that is always true:This settles my interest in this issue. Feel free to close it.
Use this - https://github.com/seegno/bookshelf-cascade-delete