module.exports = (sequelize, DataTypes) => { const vegetables = sequelize.define('vegetables', { name: DataTypes.STRING, mainPicture: DataTypes.STRING, description: DataTypes.TEXT, lat: DataTypes.INTEGER, lng: DataTypes.INTEGER, vegetableTypeId: { type: DataTypes.INTEGER, references: 'vegetableTypes', referencesKey: 'id' } }, {}) vegetables.associate = function (models) { vegetables.belongsTo(models.vegetableTypes, { as: 'Type', foreignKey: 'vegetableTypeId' }) vegetables.hasMany(models.vegetablePictures, { as: 'Pictures', foreignKey: 'vegetableId', onDelete: 'cascade' }) } return vegetables }