Make a field readOnly with Sequelize
Last updated
Last updated
Sequelize does not allow by itself to define a field as readOnly. But you can do so by using on of Sequelize's addons named sequelize-noupdate-attributes.
An admin backend running on forest-express-sequelize
sequelize-noupdate-attributes npm package
This directory contains the files where your models are defined with Sequelize. To make fields readOnly you need to require the sequelize-noupdate-attributes
package and add the noUpdate
option to the relevant fields.
The noUpdate
option will throw an error if the user tries to update a field that already has a value. However the user will be able to update a field that has a null
value.