Reputation: 5243
I'm using Sequelize in a project. There are some models there, such as the following:
class Agents extends CommonModel {
static init(sequelize) {
return super.init({
...super.baseFields,
userId: {
type: DataTypes.BIGINT,
references: User
},
...
}, {
sequelize,
timestamps: true,
paranoid: true
})
}
Also in CommonModel:
class CommonModel extends Model {
static baseFields = {
createdBy: {
type: DataTypes.INTEGER,
references: {
model: 'Users',
key: 'id'
}
},
...
}
}
Now, here is the question, what is the sequelize
parameter in init function? (I don't call it directly). When is init going to being called? (there is no constructor though)
Is this a special design pattern?
Upvotes: 1
Views: 377
Reputation: 164
super
refers to parent class and constructs it with super.init()
arguments.sequelize
in Agent
model so parameter is needed right? and maybe class model
has sequelize
variableUpvotes: 1