How can I check if a relation is established/connected?

Viewed 61

I have this prisma schema which looks like this:

model UserProfile {
  createdAt           DateTime        @default(now())
  updatedAt           DateTime        @updatedAt
  id                  String          @id @default(cuid())
  username            String          @unique
  avatar              String          @default("defaultAvatar")
  banner              String          @default("defaultBanner")
  name                String          @default("A New Gem User")
  verified            Boolean         @default(false)
  gemStaff            Boolean         @default(false)
  gender              Gender[]
  location            String?
  verifiedDescription String?
  bio                 String?
  author              User            @relation(fields: [authorId], references: [id])
  authorId            String          @unique
  posts               Post[]          @relation("UserProfilePosts")
  postGroups          PostGroup[]     @relation("UserProfilePostGroups")
  giveaways           Giveaway[]
  categories          UserCategory[]
  following           UserProfile[]   @relation("UserFollows")
  followers           UserProfile[]   @relation("UserFollows")
  comments            Comment[]       @relation("UserProfileComments")
  subComments         SubComment[]    @relation("UserProfileSubComments")
  likedPosts          Post[]
  likedComments       Comment[]       @relation("UserProfileLikesComments")
  likedSubComments    SubComment[]    @relation("UserProfileLikesSubComments")
  groupsJoined        UserGroup[]
  blocking            UserProfile[]   @relation("UserBlocked")
  blockedBy           UserProfile[]   @relation("UserBlocked")
  favoriteGroups      FavoriteGroup[] @relation("UserProfileFavoritedGroups")
  views               Int             @default(0)
}

model Post {
  createdAt            DateTime        @default(now())
  updatedAt            DateTime        @updatedAt
  public               Boolean         @default(true)
  id                   String          @id @default(cuid())
  author               UserProfile     @relation("UserProfilePosts", fields: [authorId], references: [id])
  authorId             String
  favoritedGroupsAdded FavoriteGroup[]
  content              String
  views                Int             @default(0)
  likedBy              UserProfile[]
  tags                 PostTag[]
  comments             Comment[]       @relation("PostComments")
  subComments          SubComment[]    @relation("PostSubComments")
  group                PostGroup?      @relation("PostGroups", fields: [groupId], references: [id])
  groupId              String?
}

When you like something, you create a relation from UserProfile to Post. When you dislike something, you just delete the relation. Does anyone know how can I check a relation between one UserProfile to one Post so I can figure out if someone liked a post?

0 Answers
Related