Hey! Anyone have some idea how you would solve sh...
# orm-help
b
Hey! Anyone have some idea how you would solve showing the potential amount of results of a query? Say you have a page with a list of items. And in the sidebar you have some filters. Now next to the filters I want to have a number which represents the amount of results behind that filter: Categories: ☐ Apparell (20) ☐ Accessories (5) ☐ Other (7) etc… The obvious answer would be to run each individual query and just do a count on the result. I’m just afraid of the performance and DB calls this would result in. Dunno if this is too off topic, but if anyone have any ideas I’m open for em 🙂
k
why not use a single groupBy query that does the counting by category?
like this:
Copy code
ctx.prisma.insight.groupBy({
        where: {
            forCampaign: true,
            orderedCampaign: {
                id: args.orderedCampaignId,
            },
        },
        by: ['type'],
        count: {
            type: true,
        },
    });
r
@Bård 👋 In this case, you can perform this by counting all products and grouping by category. Currently group by across tables is not possible but this can be achieved with a simple raw query 🙂
b
Hey guys, I will look at the group by function. My current filter filters across tables, so using the groupBy function alone won’t do it. But thanks for the input, appreciate it 🙂
👍 1