(Reposting to make things clearer) I seem to have ...
# orm-help
n
(Reposting to make things clearer) I seem to have run into a bug related to the ‘selectRelationCount’ preview feature. This line causes the below error, but removing the ‘_count: true’ part makes it work. Anyone got any ideas on what is going on?
this.prisma.user.findUnique({where: {id: 1}, include: {_count: true}})
r
@Nichita Z 👋 Have you added this preview feature to
schema.prisma
and then run
prisma generate
?
n
Hello, yes indeed! It’s been working OK so far for a while
r
So an update in the version caused this?
n
It started crashing after the last deploy. The biggest change I did to the User schema in between was adding an explicit many to many relationship, like this:
pendingFollowers PendingFollowers[] @relation(name: "targets")
pendingFollowing PendingFollowers[] @relation(name: "sources")
So these are both in the user object, and they relate to a model that looks like this:
model PendingFollowers {
source        User     @relation(name: "sources", fields: [sourceId], references: [id])
sourceId      Int
target    User @relation(name: "targets", fields: [targetId], references: [id])
targetId  Int
createdAt   DateTime @default(now())
@@id([sourceId, targetId])
}
I did not update prisma versions or anything, that shouldn’t be a problem. I’m thinking maybe this is a weirder relation and it bugs the count out somehow? But i’m not requesting a count for those particular fields so it shouldn’t be an issue..
r
I would suggest opening an issue for this here with all the details so that we can look into this.
n
Okay, will do after a bit more debugging, thx!
👍 1
I’ll let you know if I figure out a fix, the error isn’t particularly descriptive so it might be good to know haha
r
Adding a relation shouldn’t normally break the query.
n
Yeah, apparently it happens if I try to include these counts in the query:
followers User[] @relation(name: "approved-followers")
following User[] @relation(name: "approved-followers")
These are in the user model, does it seem OK to you? The examples in the docs are for relations between different objects, but I thought this would work
r
Yes this is a self relation as described here.
n
You’re right, they’re in the docs, my bad! I’ll try some more stuff and then create the issue
💯 1