Open mikefowler opened 6 years ago
I think there's an error in your code:
set languages(value) {
console.log('Setting languages to', value);
// this.setDataValue(JSON.stringify(value)); <-- MISSING KEY TO SET
this.setDataValue('languages', JSON.stringify(value));
}
http://docs.sequelizejs.com/class/lib/model.js~Model.html#instance-method-setDataValue
@mickhansen
@heisian yes, that seems to be a typo (which I've now corrected in my psuedocode), but the issue is that the setters and getters are not being called, period. In a simple test, those console.log
statements are never run.
I currently have exactly the same issue, after spending much time debugging models.js source I gave up and added VIRTUAL attributes with getters and setters
Looks like we are still using options.getterMethods / options.setterMethods
, I thought we remove support for that with v4.
Tagged as bug
Any update on this?
My setter does not seem to be called either using sequelize 6
What are you doing?
Attempting to use a custom setter on my model class.
The Sequelize release notes for 4.x, under "New Features", reads: "You can then define custom methods, class methods and getters/setter directly in the class".
Defining the
get/set
methods in the field's schema definition works as expected, but I expect the following to work as well.What do you expect to happen?
Setting languages to ['en', 'es']
is logged to the console"["en","es"]"
is persisted to the databaseWhat is actually happening?
SequelizeValidationError: string violation: languages cannot be an array or an object
Dialect: mysql (but irrelevant, because the error is thrown before reaching the adapter) Dialect version: n/a Database version: n/a Sequelize version: 4.22.0 Tested with latest release: No
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.