Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Mongodb Prisma 2 many to many relation is working 1 sided

I have a small issue with the relational data table, here is my model, and the question is below this.

model User {
  id                    String     @id @default(dbgenerated()) @map("_id") @db.ObjectId
  createdAt             DateTime   @default(now())
  updatedAt        DateTime   @updatedAt
  email                 String     @unique
  firstName             String
...
  rsvpedSessions        Session[]  @relation("Rsvped", fields: [rsvpedSessionId])
  rsvpedSessionId       String[]   @db.Array(ObjectId)
  notRespondedSessions  Session[]  @relation("notResponded", fields: [notRespondedSessionId])
  notRespondedSessionId String[]   @db.Array(ObjectId)
  declinedSessions      Session[]  @relation("Declined", fields: [declinedSessionId])
  declinedSessionId     String[]   @db.Array(ObjectId)


model Session {
  id                 String   @id @default(dbgenerated()) @map("_id") @db.ObjectId
  createdAt          DateTime @default(now())
  updatedAt    DateTime @updatedAt
  title              String
  ...
  rsvpedUsers        User[]   @relation("Rsvped", fields: [rsvpedUserId])
  rsvpedUserId       String[] @db.Array(ObjectId)
  notRespondedUsers  User[]   @relation("notResponded", fields: [notRespondedUserId])
  notRespondedUserId String[] @db.Array(ObjectId)
  declinedUsers      User[]   @relation("Declined", fields: [declinedUserId])
  declinedUserId     String[] @db.Array(ObjectId)

when I create the session by adding the user to the notResponded. I can see the user in notResponded array but, on User, I can't get the session under notRespondedSessions. It just links the user to the session but it doesn't link the session to the user.

I create the session with

return await prisma.session.create({
        data: {
          ...args,
          notRespondedUserId: args.userID,
        },
      });

and one more detail, when I try to Connect on notRespondedUsers, it says connect is not a valid arg.

do you have any idea what might be the reason?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to create a session and connect it to an existing user record, you should use the connect API with the relation field in question (notRespondedUsers) instead of trying to assign a value directly to notRespondedUserId.

I think this is the query you're looking for:

    await prisma.session.create({
        data: {
            ...args
            notRespondedUsers: {
                connect: {
                    id: args.userID   // if there is more than one user, you can also pass an array of { id: string} objects to connect
                }
            }
        },
    });

You can find the syntax and details for connect in the Prisma docs.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda