Is there a way that I could use a base class that has all the common attributes and methods for my models, but is not related to the database table, and then I could extend this base class when defining new models.
Here I created a basic human model in node express. I need the human class to expand 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; } } });
The documentation states that
Sequelize models are ES6 classes. You can easily add your own class or class methods.
How to do this using ES6 extends the class template?
There is a question similar to this question, but not updated recently. How to extend the Sequelize model
v1shva
source share