36 lines
852 B
JavaScript
36 lines
852 B
JavaScript
|
|
"use strict";
|
||
|
|
|
||
|
|
module.exports = function(sequelize, DataTypes) {
|
||
|
|
//The id field is auto added and made primary key.
|
||
|
|
var Item = sequelize.define('Item', {
|
||
|
|
id: {
|
||
|
|
type: DataTypes.INTEGER,
|
||
|
|
primaryKey: true,
|
||
|
|
allowNull: false,
|
||
|
|
autoIncrement: true
|
||
|
|
},
|
||
|
|
name: {
|
||
|
|
type: DataTypes.STRING,
|
||
|
|
allowNull: false
|
||
|
|
},
|
||
|
|
counts: {
|
||
|
|
type: DataTypes.JSON,
|
||
|
|
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) {
|
||
|
|
Item.belongsTo(models.Subcategory, {as: 'subcategory', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
return Item;
|
||
|
|
};
|