Order by Relations not work
See original GitHub issueBug description
Order by Relations not work in version 2.21.2
How to reproduce
My code:
prisma.product.findMany({
orderBy: {
analytics: {
id: 'acs'
}
}
})
Type '{ analytics: {}; }' is not assignable to type 'Enumerable<ProductOrderByInput>'.
Object literal may only specify known properties, and 'analytics' does not exist in type 'Enumerable<ProductOrderByInput>'
Expected behavior
No response
Prisma information
model Product {
id Int @id @default(autoincrement())
analytics Analytic[] @relation("fk_product_analytic")
@@map("products")
}
model Analytic {
id Int @id @default(autoincrement())
product_id Int
product Product @relation("fk_product_analytic", fields: [product_id], references: [id])
@@map(name:"product_analytics")
}
Environment & setup
- Node: 14.16.0
Prisma Version
2.21.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Laravel Orderby not working inside Eloquent whereHas ...
Already ASC and DESC tried. Try to order by in whereHas but it's not affect on any records. Below is model relationship. public...
Read more >Eager Loading orderBy not working as expected - Laracasts
I am trying to run eager loading with constraint by doing multiple with closure. ... The order by is added only to the...
Read more >Ordering database queries by relationship columns in Laravel
In this article we're going to explore how to order database queries by the value (column) of an Eloquent relationship.
Read more >Guide to table relationships - Microsoft Support
The relationship between the Customers table and the Orders table is a one-to-many ... This relationship is not common because, most often, the...
Read more >Eloquent, order by relationship and eager loading
How to order a query results on a one-to-one relationship in Eloquent. Since ´with()´ is creating another query ... So this will not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @NguyenKyThinh94,
Not sure if you’ve already managed to get around your issue (or if this will be helpful to anyone else reading this) but I was also seeing this error in v2.30.3.
In my situation, when I actually ran my app the order by relation was working but I was seeing the above type error. To get rid of the error I just cast my object to the expected type and it seemed to be happy enough with it.
So in your example, something along the lines of:
Thanks
@fabriciosautner I believe you can do it reverse though
user_challenges
making it distinct bychallengeId
and ordering it, then selecting thechallenge
fromuser_challenges
and returning the values in a map