Currently I have three related tables in one, users, roles and events. I need to get the users of an event and the roles of each one in the same json
I made the relationship in the database and in the API
db.role.belongsToMany(db.user, {
through: "user_roles_evento",
foreignKey: "rolId",
otherKey: "userId"
});
db.user.belongsToMany(db.role, {
through: "user_roles_evento",
foreignKey: "userId",
otherKey: "rolId"
});
But I can't get the result I want. The result I need to obtain is the following:
{
"users": [
{
"id": 1,
"email": "[email protected]",
"name": "Mauricio",
"lastname": "Garrido",
"avatar": null,
"event": {
"id": 50,
"desc": "History Class"
}
"roles": [
{
"id": 1,
"name" : "admin"
},
{
"id": 3,
"name" : "teacher"
}
]
}
]
}