I have an instance of Sequelize with the flag omitNull to insert de defaultValues defined in the DB if i do not define them in the create method of a model. Like this:
var sequelize = new Sequelize('db', 'user', 'pw', {
omitNull: true
})
But I want to insert null values in other models if I define them as null. Like:
SomeModel.create({some_property: null});
Is there a way to define the omitNull property just for some properties of a model?
When using omitNull = true
option there is a way to force sequelize to set a property null.
Just do something like this:
SomeModel.some_property = null;
SomeModel.save(['some_property']);
This will force sequelize to create the update/insert SQL with NULL for some_property
.
I hope it helps.
If you're using sequelize < v2.0, a hackier, alternative solution would be to
sequelize.options.omitNull = false;
SomeModel.some_property = null;
SomeModel.save();
sequelize.options.omitNull = true;
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