Ajout de la galerie d'images

This commit is contained in:
Damien Broqua 2018-09-16 23:46:39 +02:00
parent 4b9bed8926
commit b3dc18e57d
5 changed files with 265 additions and 16 deletions

View file

@ -18,7 +18,7 @@ module.exports = (sequelize, DataTypes) => {
})
vegetables.hasMany(models.vegetablePictures, {
as: 'Pictures',
foreignKey: 'vegetablesId',
foreignKey: 'vegetableId',
onDelete: 'cascade'
})
}

View file

@ -2,14 +2,17 @@ module.exports = (sequelize, DataTypes) => {
const vegetablePictures = sequelize.define('vegetablePictures', {
url: DataTypes.STRING,
order: DataTypes.INTEGER,
vegetablesId: {
vegetableId: {
type: DataTypes.INTEGER,
references: 'vegetables',
referencesKey: 'id'
}
}, {})
vegetablePictures.associate = function (models) {
vegetablePictures.hasOne(models.vegetables, { as: 'Vegetables', foreignKey: 'id' })
vegetablePictures.associate = function(models) {
vegetablePictures.hasOne(models.vegetables, {
as: 'Vegetables',
foreignKey: 'id'
})
}
return vegetablePictures
}