Is there a way that I could use a base class that has all the common attributes and methods for my models but not linked with a database table, and then I could extend this base class when defining new models.
Here I have created the base, person model in node express. I need the person class to be extended from the base class.
const person = sequelizeClient.define('person', {
name: {
type: DataTypes.STRING,
allowNull: false
}
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
const base = sequelizeClient.define('base', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true
},
createdBy: {
type: Sequelize.INTEGER,
},
updatedBy: {
type: Sequelize.INTEGER,
},
deletedBy: {
type: Sequelize.INTEGER,
}
}, {
hooks: {
beforeCount(options) {
options.raw = true;
}
}
});
In the documentation it's stated that
Sequelize Models are ES6 classes.You can very easily add custom instance or class level methods.
How can I do this using ES6 extends class pattern?
There's a question similar to this but has not been updated recently. How to extend Sequelize model