I am trying to achieve the following:
class User extends Model {
// Specifically this override
toJSON() {
return { ...this.get(), id: undefined };
}
}
User.init({
// Attributes here
}, {sequelize});
The previous code uses the Modal class extension to override the toJSON method; however, I am working on a project where I defined most of my modals using sequelize.define like the following:
const User = sequelize.define('User', {
// Attributes
});
Instead of refactoring all my models to extend the Modal class, is it possible to override my modals methods?
I tried using the getterMethods like so
getterMethods: {
get: () => {
return {...this.get(), id: undefined }
}
}
Sadly I am using TypeScript that could not compile this code since Object is possibly 'undefined'. ts(2532).
Thank you for your time.