InternalFX
InternalFX

Reputation: 1485

Sailsjs model afterDestroy callback seems useless, beforeDestroy not much better

The afterCreate and afterUpdate callbacks both return the model. afterDestroy gives you nothing but a callback, and beforeDestroy only gives the criteria.

I'm curious if I'm doing it wrong....

If I use afterDestroy I am basically told that a 'record'....'somewhere'....was destroyed.

If I use beforeDestroy I then have to look the model up again myself.

I know sails aint' rails, but it makes sense to me that lifecycle callbacks would have access to the model, or if not the model, at least its values.....

What say you sails community?

Upvotes: 0

Views: 1021

Answers (1)

sgress454
sgress454

Reputation: 24948

As of Waterline v0.10.0-rc6 (released about a month ago) , afterDestroy does supply the array of destroyed instances as the first argument. Just updated the docs, thanks for pointing it out.

As far as beforeDestroy is concerned, it is the same as all of the "before" callbacks, in that it gives you the criteria that will be used to find models but doesn't look them up for you. This is to avoid unnecessary queries when you might be able to do what you need (including canceling the operation altogether) without ever hitting the database. I'd call that very useful!

Upvotes: 6

Related Questions