Files
PetitTeton/models/item.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

"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
},
measures: {
//A list of measureId's in the order they should be listed when entering data (first is most likely, last is least likely).
type: DataTypes.JSON,
allowNull: false
},
aliases: { //An array of alias names (strings) for this item. Used only to find the item, and not checked to ensure that names are unique.
type: DataTypes.JSON,
allowNull: true
},
defaultPrice: {
type: DataTypes.DECIMAL(9,2),
allowNull: false
},
createdAt: {
type: DataTypes.DATE,
allowNull: false
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
paranoid: true,
classMethods: {
associate: function(models) {
Item.belongsTo(models.Subcategory, {as: 'subcategory', foreignKey: {name: 'subcategoryId', field: 'subcategoryId'}});
}
}
});
return Item;
};