PrismaP
Prisma9mo ago
2 replies
sxnx

Model not visible

I have this Schema for this discord bot im working on:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
  provider = "prisma-client-js"
  output   = "../src/generated/prisma"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        String   @id @default(cuid())
  username  String   @unique
  discordId String   @unique
  email     String?  @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  Posts        Post[]
  UserSettings UserSettings?

  @@index([discordId])
}

model UserSettings {
  id String @id @default(cuid())

  user   User   @relation(fields: [userId], references: [id])
  userId String @unique

  showOnWeb      Boolean @default(true)
  privateProfile Boolean @default(false)
  publishOnWeb   Boolean @default(true)
}

model Guild {
  id String @id @default(cuid())

  guildId     String   @unique
  name        String
  description String?
  tags        String?
  slug        String?
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt

  Posts         Post[]
  GuildSettings GuildSettings?

  @@index([guildId, name])
}

model GuildSettings {
  id String @id @default(cuid())

  guild   Guild  @relation(fields: [guildId], references: [id])
  guildId String @unique

  minStarCount      Int?        @default(5)
  StarBoardChannels StarBoard[]
}

model StarBoard {
  id String @id @default(cuid())

  guild           GuildSettings @relation(fields: [guildSettingsId], references: [id])
  guildSettingsId String

  channelId     String
  messageSyntax String

  StarboardSourceChannels StarboardSourceChannels[]
}

model StarboardSourceChannels {
  id String @id @default(cuid())

  starboard           StarBoard @relation(fields: [starBoardChannelsId], references: [id])
  starBoardChannelsId String

  channelId String
}

model Post {
  id Int @id @default(autoincrement())

  user   User   @relation(fields: [userId], references: [id])
  userId String

  guild   Guild  @relation(fields: [guildId], references: [id])
  guildId String

  messageId String @unique

  PostSources PostSources[]

  createdAt   DateTime      @default(now())
}

model PostSources {
  id String @id @default(cuid())

  post   Post @relation(fields: [postId], references: [id])
  postId Int

  messageId String @unique
  channelId String
}


and the issue im facing is with the Post model, and he PostSource model. When i create a entry in Post and than try to also create a PostSources entry it doesnt work, in fact it isnt even visible that there is a relation from PostSources to Post in the Prisma Studio.

for ex i try to create the post here
await prisma.post.create({
        data: {
          messageId: reaction.message.id,
          guildId: guild.id,
          userId: dbUser?.id,
        },
      });

(as shown in the first ss, no PostSources appear)

now i try to update that record with the PostSources:
await prisma.post
          .update({
            where: {
              id: existingPost.id,
            },
            data: {
              PostSources: {
                create: {
                  channelId: sentMessage.channel.id,
                  messageId: sentMessage.id,
                },
              },
              guildId: guild.id,
              userId: dbUser.id,
            },
          })
          .catch((e) => console.log(e));

and there is still no PostSources present in the Post model.
But when i check the Prisma Studio on the prisma website (im usign prisma postgres) its shown there. and than when i try to fetch Post with the PostSources it always appears empty. Even though im using include: to include it.
image.png
Was this page helpful?