Reputation: 1602
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
});;
Upvotes: 24
Views: 22703
Reputation: 936
id : {
field: 'some_long_name_that_is_terrible_thanks_dba_guy',
type : Sequelize.INTEGER ,
primaryKey: true
}
Specify a 'field' attribute ... Like that ^
Upvotes: 58
Reputation:
You can specify a table name by supplying the name as the first parameter to the define() call. For example:
var User = sequelize.define(
'a_long_cumbersone_users_table_name',
{
id: {
type: Sequelize.INTEGER,
primaryKey: true
},
name: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
rememberToken: {
type: Sequelize.STRING,
field: 'remember_token'
}
},
{
underscored: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at'
}
);
Upvotes: 3