I'll set this up.
- Backend: Node, GraphQL, Sequelize with a PostGRES DB.
- Frontend: React, GraphQL.
- I have models of a user, event and member.
- A user can belong to many different events.
- An event can have many users.
- A user will have a specific role for each event.
I'm dynamically creating a member join table via Sequelize, like this:
`Event.belongsToMany(models.User, { through: models.Member, foreignKey: { name: "eventId", field: "event_id" } });` `User.belongsToMany(models.Event, { through: models.Member, foreignKey: { name: "email", field: "email" } });`
My member model code does have one unique field, role
. That file looks like this:
`export default (sequelize, DataTypes) => {
const Member = sequelize.define("member", {
role: DataTypes.STRING
});
return Member;
};`
In the end, I have a member table with a role field, and also fields tied to user (email) as well as event (eventId).
My two questions
- Front-end: I'm able to query the member table (allMembers), and map through each row's role, email and eventId. But how can I display the event name? (yes, it's part of my event model). For display purposes, the eventId is obviously meaningless to the end user.
- Front-end: Once a user sees their list of events they belong to, I'd like for them to be able to click on an event — placing that event's id into state. That way, I can use that eventId for other queries. Any suggestions on the best approach to achieve this?