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