You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a field called "description" it contains a JSON of a multi language string like this: {"de":"Katze","en":"cat","fr":"chat"}
i have virtual fields like this:
descriptionDE, descriptionFR, descriptionEN etc.
type: DataTypes.VIRTUAL,
get() {
let multiJson = JSON.parse(this.get("description"));
return multiJson.de;
},
set(value) {
let lang = "de";
let currentDesc= JSON.parse(this.get("description"));
currentDesc[lang] = value;
this.setDataValue("designation", JSON.stringify(currentDesc));
},
this seems to be working fine except if i use sequelize.model.Animal.update
For some reasons this will only work if i change all languages at the same time. If i just change one of the virtual fields, i will end up with only the changed one. I believe that in the update function, the this.get('description') will fetch the defaultValue of the description field instead, that is set to be {"de":"","fr":"","en":""}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a field called "description" it contains a JSON of a multi language string like this:
{"de":"Katze","en":"cat","fr":"chat"}
i have virtual fields like this:
descriptionDE, descriptionFR, descriptionEN etc.
this seems to be working fine except if i use
sequelize.model.Animal.update
For some reasons this will only work if i change all languages at the same time. If i just change one of the virtual fields, i will end up with only the changed one. I believe that in the update function, the this.get('description') will fetch the defaultValue of the description field instead, that is set to be
{"de":"","fr":"","en":""}
Does anybody know what's happening here?
Beta Was this translation helpful? Give feedback.
All reactions