Hi, maybe some of you can help me. I tried to find...
# orm-help
s
Hi, maybe some of you can help me. I tried to find post with id but I am getting this error. Code
Copy code
const found = await this.prisma.post.findFirst({
      where: {
        postUid,
      },
    });
Error
Copy code
Invalid `prisma.post.findFirst()` invocation:

{
 where: {
  postUid: {
   postUid: '4d69bcaa-f3b8-4cb9-a3f7-bf164a8bae99'
   ~~~~~~~~~~~
  }
 }
}

Unknown arg `postUid` in where.postUid.postUid for type StringFilter. Available args:
r
@See Jee 👋 Could you share your schema?
s
@Ryan here is the schema
Copy code
model Post {
    postUid     String         @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
    title       String
    description String?
    categories  CategoryPost[]
}

model Category {
    id    Int            @id @default(autoincrement())
    title String
    posts CategoryPost[]
}

model CategoryPost {
    id         Int      @default(autoincrement())
    post       Post     @relation(fields: [postUid], references: [postUid])
    category   Category @relation(fields: [categoryId], references: [id])
    postUid    String   @db.Uuid
    categoryId Int

    @@id([postUid, categoryId])
}
r
You just need to pass the
postUid
directly. Not
postUid
inside
postUid
again.
s
okay. I am doing that somehow I am passing object instead of just string. In my controller this is how I pass it
@Body() _postUid_: string
but if I use it in query it become
postUid:  { postUid: postUid }
in query and I still dont get it why it become like that 🙂
should I use DTO?
r
I think
postUid
is an object here. I am not aware of DTO but the body in any request would always be an object so maybe the
@Body() body
will always be an object and not directly a string. Are you passing an object to the API?
s
Ah… I’m new to this so sorry I am try to catch up. But yeah I am passing it like this
Copy code
{
  "postUid": "4d69bcaa-f3b8-4cb9-a3f7-bf164a8bae99"
}
r
Then body would be an object and not a string.
s
Thanks @Ryan