api/models/vegetables.js

27 lines
704 B
JavaScript
Raw Normal View History

2018-09-07 21:14:05 +02:00
module.exports = (sequelize, DataTypes) => {
const vegetables = sequelize.define('vegetables', {
name: DataTypes.STRING,
mainPicture: DataTypes.STRING,
description: DataTypes.TEXT,
lat: DataTypes.INTEGER,
lng: DataTypes.INTEGER,
2018-09-08 00:00:47 +02:00
vegetableTypeId: {
2018-09-07 21:14:05 +02:00
type: DataTypes.INTEGER,
references: 'vegetableTypes',
referencesKey: 'id'
}
}, {})
vegetables.associate = function (models) {
2018-09-09 18:15:19 +02:00
vegetables.belongsTo(models.vegetableTypes, {
2018-09-08 00:00:47 +02:00
as: 'Type',
2018-09-09 18:15:19 +02:00
foreignKey: 'vegetableTypeId'
2018-09-07 21:14:05 +02:00
})
vegetables.hasMany(models.vegetablePictures, {
as: 'Pictures',
2018-09-09 18:15:19 +02:00
foreignKey: 'vegetablesId',
2018-09-07 21:14:05 +02:00
onDelete: 'cascade'
})
}
return vegetables
}