1

I'm having hard times to find out how to order by count field in Prisma.

The query looks like this:

const where = // ...
const limit = // ...
const skip = // ...
const data = await this.prisma.translation.findMany({
      where,
      take: limit,
      skip: offset,
      orderBy: {
        count: 'asc'
        // ^ here is the issue, because count seems to be reserved for aggregations
      }
    });

Prisma model:

model Translation {
  id           String
  count        Int      @default(0)
}

I found the docs here https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#orderby but it does not say anything how to say to prisma that the count does not mean aggregation but a column name.

The error I'm getting:

Invalid `prisma.translation.findMany()` invocation:\n\n\n  Failed to validate the query: `Assertion error: Attempted conversion of non-map ParsedInputValue (Single(String(\"asc\"))) into map failed..` at ``

PS. I found this issue on GitHub that is still open https://github.com/prisma/prisma/issues/7806, gonna ask also there for some workaround or something...

Thanks for any help :-)

1 Answer 1

1

This has been fixed in Prisma Version 3.0.1.

If you need to solve this in Prisma v2, you could change the field name in prisma and use the @map annotation to point to the count column in your database table.

Example Prisma schema

model Translation {
  id                      Int      @id @default(autoincrement())
  transactionCount        Int      @default(0)  @map(name: "count")
}

Inside your prisma code you would use transactionCount instead of count. But there won't be any change to the underlying database, which will still have the column named count.

For more info, take a look at the Prisma docs for using custom field names.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.