Many-to-many self relation with generated crud and sdl?

I am trying to make redwood generate sdl for me with the current datamodel:

model User {
  id                  Int       @id @default(autoincrement())
  email               String    @unique
  hashedPassword      String
  salt                String
  resetToken          String?
  resetTokenExpiresAt DateTime?
  role                String    @default("member")


  followers Follow[] @relation("follower")
  following Follow[] @relation("following")
}
model Follow {
  followerId Int
  follower   User @relation("follower", fields: [followerId], references: [id])

  followingId Int
  following   User @relation("following", fields: [followingId], references: [id])

  @@id([followerId, followingId])
}

But I am being told this when trying to generate it. The id shouldnt be necessary, the example it shows me at Prisma Relations and Redwood's Generators | RedwoodJS Docs doesnt really do the trick, since it either take a one-to-one relation self relation, or a many-to-many without the self.

I rant the following command to get what is shown in the picture: yarn rw g sdl Follow

Does redwoodjs handle the generation of many-to-many self relations, or do I have to write it up myself?

Check out this doc: Prisma Relations and Redwood's Generators | RedwoodJS Docs

Yes.

Seems that I didn’t change the @@id([followerId, followingId]) to be @@unique([followerId, followingId])

1 Like