Skip to content

Lack of Explicit Many-to-Many relation example in Self Relation Docs #2201

Closed

Description

@TasinIshmam

In the Self-Relation guide, there is no example of explicit many-to-many self-relation.

This makes the proper syntax for explicit many-to-many self relations potentially confusing, especially to new users. An explicit version of the many-to-many schema that's already provided in the article looks like this:

model User {
  id            String  @id @default(autoincrement())
  name          String
  followedBy    Follows[] @relation("follower")
  following     Follows[] @relation("following")
}

model Follows {
  follower    User @relation("followedBy", fields: [followerId], references: [id])
  followerId  String
  following   User @relation("following", fields: [followingId], references: [id])
  followingId String

  @@id([followerId, followingId])
}

This example can be added along with a link to the many-to-many concept guide. I believe this would make the article more comprehensive.

Would love to hear thoughts/feedback on this!

Activity

  1. added
    type/docs
    on Aug 24, 2021
  2. TasinIshmam commented on Aug 24, 2021

    @TasinIshmam
    ContributorAuthor

    Hi @molebox, could you provide your thoughts?

    I'd be happy to make a PR if you approve the change.

  3. molebox commented on Aug 25, 2021

    @molebox
    Contributor

    looks-good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/docs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions