I am trying to count a self relation (followers) in Prisma2 (using PostgreSQL)
Model:
model User {
id String @id @default(cuid())
following User[] @relation(name: "UserFollows")
followers User[] @relation(name: "UserFollows")
}
Query:
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
_count: {
select: { followers: true, following: true },
},
},
});
(using previewFeatures = ["selectRelationCount"]
) and getting the following error:
Invalid
prisma.user.findUnique()
invocation:Error occurred during query execution: ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42712"), message: "table name "User" specified more than once", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(423), routine: Some("checkNameSpaceConflicts") }) }) })
Does anybody have any idea of what I am doing wrong?