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.hasOne(models.vegetableTypes, { as: 'Type', foreignKey: 'id' }) vegetables.hasMany(models.vegetablePictures, { as: 'Pictures', onDelete: 'cascade' }) } return vegetables }