This commit is contained in:
David Arranz 2019-07-23 20:26:30 +02:00
parent 0132047367
commit cd5d39bc97
5 changed files with 60 additions and 11 deletions

View File

@ -13,10 +13,6 @@ module.exports = function (sequelize, DataTypes) {
type: DataTypes.STRING,
allowNull: false,
},
type: {
type: DataTypes.STRING,
allowNull: false,
},
content: {
type: DataTypes.STRING,
allowNull: false

View File

@ -84,17 +84,18 @@ module.exports = function (sequelize, DataTypes) {
Speaker.EventDetails = Speaker.hasMany(models.EventDetail, { foreignKey: 'speakerId', as: "eventdetails" });
Speaker.Questions = Speaker.hasMany(models.EventQuestion, { foreignKey: 'speakerId', as: "questions" });
//OJOJOJOJOJOJOJJOJ
// 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
Speaker.Multimedias = Speaker.hasMany(models.Multimedia, {
foreignKey: 'entityId',
as: { singular: 'multimedia', plural: 'multimedias' }
});
/*
Speaker.Multimedias = Speaker.belongsToMany(models.MultimediaFile, {
through: models.MultimediaSpeaker,
foreignKey: 'speakerId'
Speaker.Comments = Speaker.hasMany(models.Comment, {
foreignKey: 'entityId',
as: { singular: 'comment', plural: 'comments' }
});
*/
};
Speaker.addScope('featured', {
@ -134,5 +135,16 @@ module.exports = function (sequelize, DataTypes) {
}
});
Speaker.addScope('includeComments', () => {
return {
include: [{
model: sequelize.models.Comment,
as: 'comments',
required: false,
}]
}
});
return Speaker;
};

View File

@ -60,7 +60,7 @@ routes.get('/speakers/:id',
invalidFields: generalInvalidFields
}),
speakerController.findOne({
scopes: ['defaultScope', 'includeValues', 'includeMultimedias'],
scopes: ['defaultScope', 'includeValues', 'includeMultimedias', 'includeComments'],
})
);

File diff suppressed because one or more lines are too long

View File

@ -151,7 +151,11 @@ SELECT UUID() as ID, conferenceId, speakerId, anonymous, answered, discared, con
//COMENTARIOS.....
insert into lqdvi_v2.comments (id, entityId, entityname, content, createdAt, updatedAt, userId)
SELECT UUID() as ID, speakerid, 'speaker', content, created, created, '0939bb2a-d33d-4290-ac81-fc9faa1c015e'
FROM lqdvi.`speaker-comment`;