Search by relation count eq | gt | lt
See original GitHub issueProblem
I think the issue should be related with https://github.com/prisma/prisma/issues/3821
model Topic {
id Int @id @default(autoincrement())
title String @db.MediumText
content String @db.LongText
voters VotersOnTopics[]
watchers WatchersOnTopics[]
viewers ViewerOnTopics[]
}
model VotersOnTopics {
voter User @relation(fields: [voterId], references: [id])
voterId Int
topic Topic @relation(fields: [topicId], references: [id])
topicId Int
votedAt DateTime @default(now())
@@id([voterId, topicId])
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String @unique
name String
email String @unique
avatarUrl String?
comments Comment[]
votedTopics VotersOnTopics[]
watchedTopics WatchersOnTopics[]
viewedTopics ViewerOnTopics[] @relation("viewed")
}
The topic could be voted by many users
so what if I want to search by a votes condition ?
const result = await db.topic.findMany({
where: {
title: 'Hello world'
},
select: {
_count: {
select: {
watchers: true,
voters: true,
},
},
},
}
})
There are no _count
could be use in where
conditions
Suggested solution
const result = await db.topic.findMany({
where: {
voters: {
_count: {
gt: 40,
lt: 100
}
}
},
select: {
_count: {
select: {
watchers: true,
voters: true,
},
},
},
}
})
Alternatives
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:42
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Use the $filter query parameter - Microsoft Graph
Learn how to use the $filter OData query parameter and its operators against different types of properties in Microsoft Graph.
Read more >Filtering and sorting (Concepts) - Prisma
Use the Prisma Client API to filter records by any combination of fields or related record fields, and sort the results.
Read more >$match (aggregation) — MongoDB Manual
For your $search queries against data on your Atlas cluster, you can use the Atlas Search compound operator filter option to match or...
Read more >Rails: Using greater than/less than with a where statement
I'm trying to find all Users with ...
Read more >Queries on Rails - Active Record and Arel (2020)
Here you'll find good examples explaining how to do it. ... The predicates #eq , #not_eq , #lt , #gt , #lteq ,...
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
Please just upvote the original issue instead of spamming replies.
+1