a
This commit is contained in:
parent
90d82741f0
commit
8c6cb2875c
@ -159,9 +159,15 @@ module.exports = function (sequelize, DataTypes) {
|
||||
},
|
||||
city: {
|
||||
type: DataTypes.STRING,
|
||||
foreignKey: true,
|
||||
// references: {
|
||||
// model: 'Location',
|
||||
// key : 'city',
|
||||
// }
|
||||
},
|
||||
country: {
|
||||
type: DataTypes.STRING,
|
||||
foreignKey: true,
|
||||
},
|
||||
url_streaming: {
|
||||
type: DataTypes.STRING,
|
||||
@ -185,6 +191,12 @@ module.exports = function (sequelize, DataTypes) {
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
|
||||
indexes: [{
|
||||
unique: false,
|
||||
fields: ['country', 'city']
|
||||
}],
|
||||
|
||||
|
||||
defaultScope: {
|
||||
where: {
|
||||
state: 'publish',
|
||||
@ -223,14 +235,15 @@ module.exports = function (sequelize, DataTypes) {
|
||||
as: "comments",
|
||||
required: false,
|
||||
});
|
||||
|
||||
/*
|
||||
Event.Location = Event.belongsTo(models.Location, {
|
||||
foreignKey: ['country', 'city'],
|
||||
//sourcekey: ['country', 'city'],
|
||||
foreignKey: ['country', 'city'],
|
||||
// sourceKey: ['country', 'city'],
|
||||
as: "location",
|
||||
required: false,
|
||||
// constraints: false,
|
||||
});
|
||||
|
||||
*/
|
||||
Event.Multimedias = Event.hasMany(models.Multimedia, {
|
||||
foreignKey: 'entityId',
|
||||
as: { singular: 'multimedia', plural: 'multimedias' },
|
||||
@ -259,13 +272,15 @@ module.exports = function (sequelize, DataTypes) {
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
Event.addScope('includeLocation', () => {
|
||||
return {
|
||||
include: [
|
||||
{ model: sequelize.models.Location, as: 'location', foreignKey: ['city', 'country'], sourcekey: ['city','country'] }
|
||||
{ model: sequelize.models.Location, as: "location", foreignKey: ['country', 'city'], required: false,}
|
||||
]
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
Event.addScope('includeMultimedias', () => {
|
||||
return {
|
||||
|
||||
@ -72,7 +72,7 @@ routes.get('/events/past', cacheSuccesses('24 hours'),
|
||||
PaginateMiddleware.middleware(),
|
||||
SortMiddleware.middleware({ default: "-init_date" }),
|
||||
eventController.find({
|
||||
scopes: ['defaultScope', 'past', 'includeVenue', 'includeMultimedias', 'includeDetails'], //, 'includeLocation'],
|
||||
scopes: ['defaultScope', 'past', 'includeVenue', 'includeMultimedias', 'includeDetails'],
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@ -17,12 +17,12 @@ const extraMethods = {
|
||||
}
|
||||
|
||||
let rows = result.rows.map(row => row.toJSON());
|
||||
/*
|
||||
|
||||
if (context.scopes.includes('CitiesOfEvents'))
|
||||
rows = rows.map(city => citiesComposer(city, context))
|
||||
else
|
||||
rows = rows.map(event => eventComposer(event, context));
|
||||
*/
|
||||
|
||||
return {
|
||||
count: result.count,
|
||||
rows: rows
|
||||
|
||||
@ -9,11 +9,13 @@ module.exports = function (sequelize, DataTypes) {
|
||||
},
|
||||
country: {
|
||||
type: DataTypes.STRING(125),
|
||||
allowNull: false
|
||||
allowNull: false,
|
||||
// primaryKey: true,
|
||||
},
|
||||
city: {
|
||||
type: DataTypes.STRING(125),
|
||||
allowNull: false
|
||||
allowNull: false,
|
||||
// primaryKey: true,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
@ -29,7 +31,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
});
|
||||
|
||||
Location.associate = function (models) {
|
||||
//Location.Events = Location.hasMany(models.Event, { as: 'events', foreignKey: ['country', 'city'] });
|
||||
// Location.Events = Location.hasMany(models.Event, {as:'events', foreingKey: ['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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user