question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

findMany with include/select many-to-many relation results in empty array (bigint)

See original GitHub issue

Bug 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:

Screenshot 2022-05-25 at 14 54 39

Output:

Screenshot 2022-05-25 at 14 56 44

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:

Screenshot 2022-05-25 at 14 44 11

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
iamel89commented, May 30, 2022

FOUND! Error raises when using BigInt as id in schema! When using Int there is an expected behavior. But I have to use BigInt.

1reaction
cprietocommented, Jun 28, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found