How would be the recommended way to count a list t...
# orm-help
m
How would be the recommended way to count a list that is linked using an indirect relationship? Looks like I can't do:
ctx*.*_prisma_*.*_user_*.*findOne({ where: { id: root*.*_id_ } })*.*_contacts.count(args)_
as
contacts.count
doesn't exist in that situation ----- Edit: I used
ctx.prisma.contact.count({ where: { user: { some: { id: root*.*_id_ } } } })
But idk if it's the correct/most optimized way of doing it
r
Hi @Matheus Assis - that seems fine. If you want you can add query logging and check what the output is. I'm pretty sure that going
user.findOne().contacts
will generate 2 queries where the
contact.count
may only produce one (an, like you said, the first option doesn't exist).
To get logging you can use:
Copy code
const prisma = new PrismaClient({
    log: ['query']
});