Anybody having issues with the new`_count` feature...
# prisma-client
d
Anybody having issues with the new`_count` feature? I'm getting red squiggles and this error:
Copy code
Type '{ _count: { select: { initialLadderAppearances: true; }; }; }' is not assignable to type 'MemberInclude'.
Object literal may only specify known properties, and '_count' does not exist in type 'MemberInclude'.ts(2322)
I just verified that I generated my Prisma client using 2.22.0, and I reloaded VSCode.
_count
doesn't seem to exist anywhere 🤷‍♂️🤷‍♂️🤷‍♂️ Here's the relevant code snippet:
r
if you can copy your other posts into this thread and then delete them from the channel (so you only have your first post), it'll make it easier to chat about 🙂 . (Slack's UI doesn't really do well with 10,000's of posts and people in a channel)
d
Point taken, but where are these 10,000's of posts you speak of? I'm the only one who's posted since Thursday. This channel seems to be pretty dead.
r
slack's issue is, if we chat in the channel, it becomes messy when someone else writes a new topic in between our discussion. And then you need to start quoting messages from last week, etc. Otherwise we can start chatting in this thread, but the context is lost because your other messages are out in the channel, and when someone will do a search in a week / month / year with the same issue you have, they won't see how you solved it 🙂
channel does seem pretty dead, but no doubt someone will write "please move your conversation to a thread", and then we're back to my request above... or at least, a thread with no context
^ my initial request above was to genuinely give you an answer to your issue
d
Ahh, I got it. The infamous missing preview flag strikes again 😐
Copy code
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["selectRelationCount"]
}
Alas, now that I have it working, it doesn't quite do what I want (or I don't know how yet). Essentially, you can do this:
Copy code
const member = await prisma.member.findUnique({
        select: {
            initialLadderAppearances: {
                where: {
                    year: { gte: currentYear },
                },
            },
        },
        where: { id: memberId },
    });
But you can't do this...
Copy code
const member = await prisma.member.findUnique({
        select: {
            _count: {
                select: {
                    initialLadderAppearances: {
                        where: {
                            year: { gte: currentYear },
                        },
                    },
                },
            },
        },
        where: { id: memberId },
    });
Maybe there's a way, but this isn't the syntax if there is.
r
I think you might have to use the
some
syntax when working with relations. See these threads: https://prisma.slack.com/archives/CKQTGR6T0/p1620000893084500?thread_ts=1619164287.276100&cid=CKQTGR6T0
(and this, but the owner never gave a response with what worked: https://prisma.slack.com/archives/CKQTGR6T0/p1619986234083600 )
d
some
is interesting. I got my particular problem solved with selects and just did a little bit of post-processing with the result.
Anyway, thanks for responding!
👍 1
r
let us know how you solve it 🙂