Enable optimistic locking in Models


#1

I’m starting an API Rest with the Adonis-CLI template for APIs

How can I add a Version field for all my models?

I would like to control the version of the registry in case some user modified the registry.

The same makes the Sequelize

http://docs.sequelizejs.com/manual/tutorial/models-definition.html#configuration


#2

Can you share how it is supposed to work?


#3

It is quite simple, but widely used in business applications. so there is no problem with changes in the same registry.

// Enable optimistic locking. When enabled, sequelize will add a version count attribute
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.

version: true