Reputation: 62
When I create a new model with the sequelize-cli it automatically creates a model by extending the Model class. I would like to create models with the sequelize.define syntax. How can I change this? Is this a configuration I can change?
Command
npx sequelize-cli model:generate --name test --attributes first_name:string,last_name:string
Desired result
"use strict";
module.exports = (sequelize, DataTypes) => {
const template = sequelize.define(
"test",
{
first_name: DataTypes.STRING,
last_name: DataTypes.STRING
},
{}
);
test.associate = function(models) {
};
return test;
};
Actual result
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class test extends Model {
static associate(models) {
}
}
test.init({
first_name: DataTypes.STRING,
last_name: DataTypes.STRING
}, {
sequelize,
modelName: 'test',
});
return test;
};
Upvotes: 1
Views: 1622
Reputation: 2442
Unfortunately there is no way with the officiel sequelize-cli. Indeed it uses this hardcoded template to generate the model file.
The only ways would be:
Upvotes: 1