I have the following relation:
Association is:
users.belongsToMany("roles", {
through: "userRoles",
});
When creating a user I do this:
register: async (obj, args, context, info) => {
const PasswordHash = await bcrypt.hash(args.input.Password, 12);
const user = db.users.create({
...args.input,
Password: PasswordHash,
});
db.userroles.create({
UserId: user.Id,
RoleId: args.input.roleId,
});
},
How to do this in one request? Right now Im doing one when creating the user and then getting the Id of the newly created user and adding a role to that user (request 2).
A followup, lets say I would have more then one junction tabel tied to users table, again how would I insert to all tables in one db request?
