Relations not updating

Hey,

thanks for such a lovely project. Have been trying to update an existing entry by adding a new relation and while the query returns successfully the data is not represented/updated in the graphql explorer.

model Post {
  id        Int @id @default(autoincrement())
  name      String
  type      String
  weight    Int
  tags Tag[]
}

model Tag {
  id           Int @id @default(autoincrement())
  width     Int
  x         Int
  y         Int
}

  return db.post.update({
    data: {
      name: 'test',
      type: 'test',
      tags: {
        connect: [
          {
            id: 1
          }
        ]
      }
    },
    where: { id }
  });

Do you know what could be happening to stop the relation from being updated? The other post data is updated without issue.

Thanks,

Have you seen the new relations syntax that Prisma introduced recently? You need to use a @relation keyword in both models that tell them how they relate to each other. Prisma will automatically create a relation table between the two, or you can explicitly define one: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/relations#many-to-many-relations

1 Like

Thanks heaps for you’re quick reply & help. I should have checked some of the other issues as well, once I added the resolver to the post service it worked!

2 Likes