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