question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Returning option for Model.destroy

See original GitHub issue

Model.update(...) already accepts returning = true option - any plans to add same option for Model.destroy(...) - would be very nice feature.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
AllanPinheiroDeLimacommented, Feb 21, 2019

Well, it would be a very nice feature. I’m using the .destroy method and I would use the “returning” option as well. As update has this already, it would make sense to pull this into a next step. About backward compatibility, if now return only “rows”, into the first parameters, it wouldn’t be the same as update to return the deleted instance in the second parameter ? I mean, I’m new to the library at all, but it didn’t make sense for me not putting it into the second parameter as it does not exist second parameter at all

1reaction
alekbarszczewskicommented, Jul 15, 2015

It may return whole rows (deleted ones) or specified columns:

DELETE FROM "Users" RETURNING *; -- will return deleted rows same as select
DELETE FROM "Users" RETURNING id, email; -- will return only id and email columns of deleted rows

So it “behaves” same as RETURNING in UPDATE

This is very handy if you want to delete something and then for example send email based on deleted data - instead of fetching row and then deleting it you can just delete and fetch in one query (one server-database roundtrip less).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize how to return destroyed row - node.js - Stack Overflow
Here we are returning a promise as Model.destroy which will resolve to result object received from the call to Model.find .
Read more >
Using `Returning` with Sequelize and Postgres | by Zach C
Sequelize uses an option called returning to specify which data returns from a commands like .destroy() or update() . Let's look at three...
Read more >
sequelize.Model.destroy JavaScript and Node.js code examples
Delete multiple instances, or set their deletedAt timestamp to the current time if `paranoid` is enabled.
Read more >
Final Class: Model - Oracle
destroy (options) : {boolean} ... Delete the record represented by this model object from the data service. If the server responds with virtual ......
Read more >
Active Record Callbacks - Ruby on Rails Guides
before_destroy callbacks should be placed before dependent: :destroy associations (or use the prepend: true option), to ensure they execute before the records ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found