I have a User
model which can post Comment
s and vote on them. Comment
s can also be parented to each other (for nested comments like on HN or Reddit`).
model User {
[...]
// Comments the user has posted
comments Comment[] @relation("UserToComment")
// Comments the user has voted on
upvotedComments Comment[] @relation("_UpvoterToComment")
downvotedComments Comment[] @relation("_DownvoterToComment")
}
model Comment {
[...]
// Comment's author
author User @relation("UserToComment", fields: [authorId], references: [id])
authorId String
// Users who voted on the comment
upvoters User[] @relation("_UpvoterToComment")
downvoters User[] @relation("_DownvoterToComment")
// One-to-many self-relation for nested comments
parentId String?
parent Comment? @relation("Parent", fields: [parentId], references: [id])
children Comment[] @relation("Parent")
}
I have a few questions on how to correctly name these relations.
How should relation that describes the User
being an author of several Comments
be named:
- "UserToComment"?
- "Author"?
- "CommentAuthor"?
- "UserComments"?
I've read somewhere that many-to-many relation names are supposed to start with an underscore (but I'm not sure why, and whether this applies to one-to-many relations as well). How should the relation that describes the multiples User
s being upvoters of multiple Comments
be named:
- "_UpvoterToComment"?
- "UpvoterToComment"?
- "UserUpvoted"?
- "Upvoters"?
Finally, I have a Comment
relating to itself for the nested comments. Should this relation be named:
- "Parent"?
- "Children"?
- "ParentChildren"?
- "CommentToComment"?
- Any of the above but with the underscore in front?
Can you guys help me to understand the correct conventions here, give me some advice on how should name my relations?