Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 400-self-relations.mdx : Fix typo, by swapping follower and following relations #4472

Closed
wants to merge 1 commit into from

Conversation

redbar0n
Copy link

@redbar0n redbar0n commented Jan 30, 2023

Simple two-liner typo fix.

@vercel
Copy link

vercel bot commented Jan 30, 2023

@redbar0n is attempting to deploy a commit to the Prisma Team on Vercel.

A member of the Team first needs to authorize it.

@janpio
Copy link
Contributor

janpio commented Jan 30, 2023

I think this is the third time these are flipped around now. We might need to come up with a better example that has less similar sounding words to describe the concept at hand @sabinadams

@redbar0n
Copy link
Author

maybe replace "follower" with "followedBy" in the relations as well, then they will align perfectly with the same names used in the model.

@redbar0n
Copy link
Author

redbar0n commented Jan 30, 2023

and also maybe rename "following" to "follows", since "following" might otherwise be mistaken for a user having "a following" (that's maybe where the mistake came from: since a following is an english term used to describe a group of followers).

@janpio
Copy link
Contributor

janpio commented Jan 30, 2023

That is exactly the problem, I don't think it was meant like you understand the terms. The relation name and the relation field name describe different sides of the same relationship - and you can look at the relationships in 2 directions, as it is a self relation.

@redbar0n
Copy link
Author

redbar0n commented Jan 30, 2023

Yeah, I know. To be clear, everything I wrote after , since is not how I actually understand the term "following", but was to illustrate how people could misunderstand it.

@sabinadams
Copy link
Contributor

Ah yeah, reading through that section it does seem the choice of example may not have been the most clear.

I think it would make sense to present a different scenario that used a bit clearer names.

@janpio Also want to note that there are a couple of other places on this page that could use some tweaks & revisions as well.

@redbar0n
Copy link
Author

@nilubava thanks, how about also renaming "following" to "follows", for the aforementioned reason?

nikolasburk added a commit that referenced this pull request Nov 16, 2023
@nikolasburk
Copy link
Member

I think there's no right or wrong here to be honest. The most important thing is that we have two relation names that match each other in both models, they could also just be called A and B.

We might need to come up with a better example that has less similar sounding words to describe the concept at han

The example is fine and important, it shows a directional m-n-relationship.

We can consider though adding a non-directional m-n-relationship, like:

model User {
  id          Int           @id @default(autoincrement())
  email       String        @unique
  name        String?
  hasFriends1 FriendShips[] @relation("hasFriends1")
  hasFriends2 FriendShips[] @relation("hasFriends2")
}

model FriendShips {
  friend1   User @relation("hasFriends1", fields: [friend1Id], references: [id])
  friend1Id Int
  friend2   User @relation("hasFriends2", fields: [friend2Id], references: [id])
  friend2Id Int

  @@id([friend1Id, friend2Id])
}

With "followers" it's important who follows who, with "friends", it doesn't matter.

maybe replace "follower" with "followedBy" in the relations as well, then they will align perfectly with the same names used in the model.

I did like this suggestion though so I've created another PR where I make this change. Thanks for the suggestion @redbar0n 🎉 💚

Here's the new version:

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

model Follows {
  followedBy   User @relation("followedBy", fields: [followedById], references: [id])
  followedById Int
  following    User @relation("following", fields: [followingId], references: [id])
  followingId  Int

  @@id([followingId, followedById])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants