Paranoid Table Hooks

Hey Forest,

We implement soft deletes in our databases and therefore use the paranoid option for our tables. This leads to 2 problems for us.

1- We want to see soft deleted records within Forest but can’t. I tried following the documentation here View soft-deleted records - Woodshop

The beforeFind and beforeCount hooks are not working for us

How could we go around this?

2- We are also using hooks to detect updates and deletes as well. However when a delete is triggered on a paranoid table no hooks are fired at all from my understanding. We tried update, destroy, etc but to no avail. How can we use hooks with paranoid tables?

Thank you in advance!

Hi @Arda_Yurdakul :wave: I just tested on my end on a simple table, and the code you wrote work fine for me :confused:.
Which version of Sequelize do you use?

Hey @Arnaud_Moncel

Maybe I need a newer version of Sequelize?
Here are my package details:

I’m afraid, i have the exacte same version like and it works.
Can you give me the full declaration of your model please?

Yep, here is the model. It’s approximately 500 lines so I sent the file itself. The table remains paranoid despite the hooks unfortunately. The other hooks work normally except for the beforeDestroy and afterDestroy which don’t get called at all.

Thank you :pray:

charge-points.tar (14.5 KB)

Pretty strange :thinking:i don’t see any miss configuration on your model definition.
So if I understand correctly, the hooks beforeFind and beforeCount is not called.
Have you got any error logs or something like that?

I just realized I had a scope applied to the table from way back :scream_cat: Turns out there was no issue with the beforeFind! I apologize. That only leaves me with my other issue which is what hook to use for when we soft-delete a record within Forest Admin’s interface. I can’t seem to find one that fires off. Is there a workaround?

Hi @Arda_Yurdakul Sequelize use an update query when the table is on paranoid eg:

UPDATE "public"."simple" SET "deletedAt"=$1 WHERE "deletedAt" IS NULL AND "id" = $2

So if you want to do something before you can use beforeUpdate maybe?
Let me know!