findMany with include/select many-to-many relation results in empty array (bigint)
See original GitHub issueBug description
I have a table Place
and a table PlaceCategory
with a _PlaceToPlaceCategory
as relation table. When using the findMany with include/select: { categories: true }
, the categories are empty (categories: []
) for most of the records (for some of them is working as expected), even if they are linked in the relation table.
If I change the findMany options and I set the id: number
in the where clause, categories are correctly extracted, also works with findUnique/findFirst
:
Output:
How to reproduce
Create a table with a many-to-many relation and call findMany including the relation
Expected behavior
No response
Prisma information
My tables are defined as below:
model Place {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
address String? @db.VarChar(255)
phone String? @db.VarChar(255)
websiteUrl String? @db.VarChar(255)
googlePlaceId String? @db.VarChar(255)
creationDate DateTime @default(now()) @db.Timestamp(0)
publishedDate DateTime @default(now()) @db.Timestamp(0)
organisationId BigInt @db.UnsignedBigInt
authorId BigInt? @db.UnsignedBigInt
archived Boolean @default(false)
email String? @db.VarChar(255)
mobilePhone String? @db.VarChar(255)
onDemand Boolean?
title String? @db.VarChar(255)
content String? @db.LongText
attachmentId BigInt? @db.UnsignedBigInt
isChanged Boolean?
favorite Boolean @default(false)
targetType String? @db.VarChar(100)
thumbnail Attachment? @relation(fields: [attachmentId], references: [id], onUpdate: Restrict, map: "Place_ibfk_6")
author User? @relation(fields: [authorId], references: [id], onUpdate: Restrict, map: "Place_ibfk_5")
organisation Organisation @relation(fields: [organisationId], references: [id], onDelete: Cascade, onUpdate: Restrict, map: "Place_ibfk_4")
attachments AttachmentToPlace[]
openings Opening?
position PlaceCoordinates?
translations PlaceLang[]
editors User[] @relation("PlaceToEditor")
categories PlaceCategory[]
@@index([authorId], map: "authorId")
@@index([organisationId], map: "organisationId")
@@index([attachmentId], map: "thumbnail")
}
model PlaceCategory {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
iconId Int?
iconName String? @db.VarChar(100)
color String? @db.VarChar(7)
organisationId BigInt @db.UnsignedBigInt
authorId BigInt? @db.UnsignedBigInt
parentId BigInt? @db.UnsignedBigInt
colorContrast String? @db.VarChar(4)
order Int?
title String? @db.VarChar(255)
author User? @relation(fields: [authorId], references: [id], onUpdate: Restrict, map: "PlaceCategory_ibfk_5")
organisation Organisation @relation(fields: [organisationId], references: [id], onDelete: Cascade, onUpdate: Restrict, map: "PlaceCategory_ibfk_4")
parentCategory PlaceCategory? @relation("PlaceCategoryToPlaceCategory_parentId", fields: [parentId], references: [id], onDelete: Cascade, onUpdate: Restrict, map: "PlaceCategory_ibfk_6")
children PlaceCategory[] @relation("PlaceCategoryToPlaceCategory_parentId")
channels PlaceCategoryChannel?
translations PlaceCategoryLang[]
subscriptionPreferences PlaceCategorySubscription[]
place Place[]
@@index([authorId], map: "authorId")
@@index([organisationId], map: "organisationId")
@@index([parentId], map: "parentId")
}
and this is my relation table:
Environment & setup
- OS: Mac OS 11.6
- Database: MySQL 5.7.26
- Node.js version: v14.19.2
Prisma Version
3.14.0
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Laravel many to many relationship returning empty array
I'm trying to get the results using laravel many to many relationship but the query is generating wrong therefore it return empty array....
Read more >postgresql - array_length if array is empty behaviour
It looks like PostgreSQL returns NULL for empty arrays. Try: SELECT array_length(ARRAY[]::bigint[], 1), array_length(ARRAY[]::bigint[], ...
Read more >Array Functions | ClickHouse Docs
Returns 1 for an empty array or 0 for a non-empty array. ... An exception is thrown if query results in arrays with...
Read more >TypeError: Reduce of empty array with no initial value
The JavaScript exception "reduce of empty array with no initial value" occurs when a reduce function is used.
Read more >#CALC! error - Empty array - Microsoft Support
Empty array errors occur when an array formula returns an empty set. For example, =FILTER(C3:D5,D3:D5<100) will return an error because there are no...
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
FOUND! Error raises when using
BigInt
as id in schema! When usingInt
there is an expected behavior. But I have to useBigInt
.This problem was fixed with https://github.com/prisma/prisma-engines/pull/3006 and it will be released with the new version of Prisma really soon.