api/models/vegetables.js
2018-09-07 21:14:05 +02:00

25 lines
681 B
JavaScript

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