npm install -g sequelize-cli To update the database after updating the app from git (on the command line in the webapp base directory): sequelize db:migrate To undo the last migrations: sequelize db:migrate:undo
32 lines
791 B
JavaScript
32 lines
791 B
JavaScript
"use strict";
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
//The id field is auto added and made primary key.
|
|
var Category = sequelize.define('Category', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
allowNull: false,
|
|
autoIncrement: true
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false
|
|
},
|
|
visible: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
defaultValue: true
|
|
}
|
|
}, {
|
|
freezeTableName: true, // Model tableName will be the same as the model name
|
|
classMethods: {
|
|
associate: function(models) {
|
|
Category.hasMany(models.Subcategory, {as: 'subcategories', foreignKey: {name: 'categoryId', field: 'categoryId'}});
|
|
}
|
|
}
|
|
});
|
|
|
|
return Category;
|
|
};
|