Count Relations Error
See original GitHub issueBug description
I’m trying to make an API call that retrieves the count of entries for a related field. I get the following error:
(node:89911) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.decider.findMany()` invocation:
Error:
Invalid `prisma.decider.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("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(354)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
at cb (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:35227:17)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:90768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:90768) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
How to reproduce
I’m running the following TS script:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function start () {
const users = await prisma.decider.findUnique({
where: {
slug: 'cocktails'
},
select: {
_count: {
select: {
entries: true
}
}
}
// include: {
// _count: {
// entries: true
// }
// }
});
console.log(JSON.stringify(users, null, 2));
};
start();
The odd part is that running the “where” condition alone retrieves results.
Expected behavior
Returning something like:
{"decider_id":1,"name":"Cocktails","description":"Cocktails Description","slug":"cocktails", "_count": { "entries": 2}}
Prisma information
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// model Post {
// post_id Int @id @default(autoincrement())
// content String?
// title String
// author_id Int?
// author User? @relation(fields: [author_id], references: [user_id])
// }
// model Profile {
// bio String?
// profile_id Int @id @default(autoincrement())
// user_id Int
// user User @relation(fields: [user_id], references: [user_id])
// }
// model User {
// email String @unique
// name String?
// user_id Int @id @default(autoincrement())
// posts Post[]
// profiles Profile[]
// }
model Decider {
decider_id Int @id @default(autoincrement())
name String
description String?
slug String @unique
fields Field[]
entries Entry[]
@@unique([decider_id, name])
}
model Field {
field_id Int @id @default(autoincrement())
name String
description String?
type_name String
type Type @relation(fields: [type_name], references: [name])
decider_id Int
decider Decider @relation(fields: [decider_id], references: [decider_id])
data Data[]
@@unique([field_id, name])
}
model Data {
data_id Int @id @default(autoincrement())
value String?
entry_id Int
entry_name String
entry Entry @relation(fields: [entry_id, entry_name], references: [entry_id, name])
field_id Int
field_name String
field Field @relation(fields: [field_id, field_name], references: [field_id, name])
}
model Entry {
entry_id Int @id @default(autoincrement())
name String
slug String
data Data[]
decider_id Int
decider_name String
decider Decider @relation(fields: [decider_id, decider_name], references: [decider_id, name])
@@unique([entry_id, name])
@@unique([slug, decider_id])
}
model Type {
type_id Int @id @default(autoincrement())
name String @unique
fields Field[]
}
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: v12.18.2
Prisma Version
2.24.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
count self relation on Prisma error: table name specified more ...
This is a known issue with self-relations and we hope to fix it soon. If you want to track this bug, follow this...
Read more >Aggregating functions - Cypher Manual - Neo4j
Using count(*) to group and count relationship types. The function count(*) can be used to group the type of matched relationships and return...
Read more >Eloquent: how to where count relation ship ? - Laracasts
I have two models : TeamleaderDeal and Task . the relationship is : TeamleaderDeal model: Copy Code public function tasks() ...
Read more >Display a relation count in a List via columns.yaml
To display this count value in a List, use the useRelationCount option in your columns.yaml . Using the usual select: count method would...
Read more >Create and manage relationships in Power BI Desktop
If none of the tables selected for the relationship has unique values, you'll see the following error: One of the columns must have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry! Here’s the log with
DEBUG=*
:Closing in favour of https://github.com/prisma/prisma/issues/7331
It describes the same bug.