I'm using Sequelize.js in paranoid mode in my node.js project and while the soft deletion works as expected in finding and deleting data, i'm having trouble finding a way to undelete soft deleted rows.
I know I can get deleted rows by using as explained in the docs
Model.findAll({paranoid: false, where: {deletedAt: {ne: null}}})
but paranoid: false isn't available when updating.
Is undeleting soft deleted rows even possible in Sequelize or am I just missing something?
A paranoid table is one that, when told to delete a record, it will not truly delete it. Instead, a special column called deletedAt will have its value set to the timestamp of that deletion request. This means that paranoid tables perform a soft-deletion of records, instead of a hard-deletion.
destory({ truncate: true }), it delete all data in table.
First, you get an instance of the Model by calling the create() or findOne() method. Once you have the instance, you call the set() method to change the values of the instance. Then, you need to call the save() method on the instance to persist the changes to your table row.
Get your object with {paranoid: false}
option, ie. var model = Model.findOne({ where: { something: 1 }, paranoid: false })
and then restore it model.restore()
http://docs.sequelizejs.com/en/latest/api/instance/#restoreoptions-promiseundefined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With