Accessing model name: model.name . Accessing model table name: model. tableName . Note: model as used above is an instance of sequelize model.
To add or delete columns in Sequelize CLI, we can use the sequelize migration:create command to create a migration file. Then we call addColumn to add a column and removeColumn to remove a column in the migration file. to create a migration file. in the migration file.
const People = sequelize. define('people', { name: DataTypes. STRING, }, { hooks: { beforeCount (options) { options. raw = true; } }, tableName: 'people', name: { singular: 'person', plural: 'people' } });
I have a given database with long, cumbersome columnnames. Isn't there any way to map the tablenames to shorter and more descriptive propertyNames in the model ? something like
var Employee = sql.define('Employee', {
id : {type : Sequelize.INTEGER , primaryKey: true, map : "veryLongNameForJustTheId"}
},{
tableName: 'cumbersomeTableName',
timestamps: false
});;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With