New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preview feature feedback: Prisma count by filtered relation (filteredRelationCount
)
#15069
Comments
This works great except that without the ability to have multiple Footnotes
|
@matthewmueller did you think about allowing multiple counts for the same relation? I agree with @chason it's limited otherwise. I guess it would make the typing a bit more complicated since multiple counts probably imply multiple names? |
This comment was marked as outdated.
This comment was marked as outdated.
Good feature, great job! For cases where I am interested in |
This comment was marked as outdated.
This comment was marked as outdated.
Is there a way that this _count returns the total number of users not just its relations? I need it for pagination, currently I have to send 2 requests: prisma.user.findMany({,,.}) to get the users, prisma.user.count({...}) to get the total number of users await prisma.user.findMany({
select: {
_count: {
select: {
posts: { where: { title: 'Hello!' } },
},
},
},
}) |
This comment was marked as outdated.
This comment was marked as outdated.
There are some differences in In common where: {
something: {
not: null
}
} But with filteredRelationCount where: {
something: {
isNot: null
}
} |
Hey @inferusvv, Would you mind sharing a Prisma Schema that reproduces your issue? I'm mostly interested in the type of |
@Weakky Sorry, I am not using this flag for now, but just implement basic count with this feature enabled. There is just no consistency in naming. |
I'm afraid I'm unable to reproduce your issue. prisma.user.findMany({
where: { address: { isNot: { user: { isNot: { id: 1 } } } } },
includes: {
_count: { where: { user: { isNot: { address: { isNot: { id: 1 } } } } } }
}
}) We're aware the naming is inconsistent between scalar and relations, but that has no relevance with |
Got you. This is weird. Here is my model:
And prisma request: this.prismaService.pointOfSale.findMany({
where: {
menuId: {
not: null,
},
},
}); There is no |
Thanks for the follow-up! That confirms my thoughts. As mentioned above, scalar fields and relations indeed have a different To-one relations use To conclude, this is a completely different topic, which won't be treated in the scope of making this feature GA. |
Will there be a way to order by For example, I want to sort the post by the number of matching tags. db.post.findMany({
include: {
_count: {
select: {
tags: {
where: { name: { in: tags } }
}
}
},
tags: true
},
orderBy: [
{ tags: { _count: "desc" } } // <- this only sort by all tag count
]
}) |
Hey folks,
@ssukienn Have you tried using
@SC0d3r Good piece of feedback. We understand the pain point so I've created an issue for you to track here #19779
@joshuaavalon This is an unfortunate limitation the Prisma Client has atm. The root problem is that you have no way of referring to an existing join (expressed by the where clause). While your use case is totally valid, the way it currently behaves is also valid and we should have a mechanism that enables you to choose whether you want to order by a subset of the data or on all the data. While this is something we have on our sight, we haven't started thinking about how we'll allow that just yet. There is an existing issue that I believe expresses your concern here #14598 |
Thanks everyone, |
Please share your feedback about the
filteredRelationCount
functionality released in v4.3.0 in this issue.If you have any questions, don't hesitate to ask them in the
#prisma-client
channel in the Prisma Slack.The text was updated successfully, but these errors were encountered: