Added routes for Types and Vegetables

This commit is contained in:
Damien Broqua 2018-09-08 00:00:47 +02:00
parent a8dc7f8323
commit e738d80579
17 changed files with 3938 additions and 304 deletions

View file

@ -5,7 +5,7 @@ module.exports = (sequelize, DataTypes) => {
description: DataTypes.TEXT,
lat: DataTypes.INTEGER,
lng: DataTypes.INTEGER,
vegetableTypes_id: {
vegetableTypeId: {
type: DataTypes.INTEGER,
references: 'vegetableTypes',
referencesKey: 'id'
@ -13,8 +13,8 @@ module.exports = (sequelize, DataTypes) => {
}, {})
vegetables.associate = function (models) {
vegetables.hasOne(models.vegetableTypes, {
as: 'VegetableTypes',
foreignKey: 'vegetableTypes_id'
as: 'Type',
foreignKey: 'id'
})
vegetables.hasMany(models.vegetablePictures, {
as: 'Pictures',

View file

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