From 90d82741f098fbda2d7eb67d47b7aad5a6ff9a70 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 27 Aug 2019 13:18:44 +0200 Subject: [PATCH] . --- modules/events/event.model.js | 6 +++--- modules/locations/locations.model.js | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/events/event.model.js b/modules/events/event.model.js index 300ef72..b3d3ed9 100644 --- a/modules/events/event.model.js +++ b/modules/events/event.model.js @@ -224,9 +224,9 @@ module.exports = function (sequelize, DataTypes) { required: false, }); - Event.Location = Event.hasOne(models.Location, { - foreignKey: ['city', 'country'], - sourcekey: ['city', 'country'], + Event.Location = Event.belongsTo(models.Location, { + foreignKey: ['country', 'city'], + //sourcekey: ['country', 'city'], as: "location", required: false, }); diff --git a/modules/locations/locations.model.js b/modules/locations/locations.model.js index 4872913..53e64e4 100644 --- a/modules/locations/locations.model.js +++ b/modules/locations/locations.model.js @@ -22,10 +22,14 @@ module.exports = function (sequelize, DataTypes) { tableName: 'locations', freezeTableName: true, timestamps: true, + indexes: [{ + unique: true, + fields: ['country', 'city'] + }] }); Location.associate = function (models) { - Location.Events = Location.hasMany(models.Event, { as: 'events', foreignKey: ['city', 'country'], sourcekey: ['city', 'country'] }); + //Location.Events = Location.hasMany(models.Event, { as: 'events', foreignKey: ['country', 'city'] }); //OJO antes de force comentar // OJO GENERA UN FOREIGN KEY Con eventos y habrĂ¡ ID de otras entidades que no exitan en la tabla eventos, porque son post o speakers