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.

`TypeError: value.map is not a function` when performing update all related records

See original GitHub issue

Bug description

Receive TypeError: value.map is not a function when performing update all related records.

image

Related to issue #7085

How to reproduce

export const completeWorkerRequest = async ({ id, comment }) => {
  requireAuth({ role: ADMIN_ROLE })

  const existing = await db.workerRequest.findUnique({ where: { id } })

  return db.workerRequest.update({
    where: { id },
    data: {
      comment,
      status: { connect: { id: 0 } },
      updatedBy: context.currentUser.email,
      actions: {
        create: {
          actor: context.currentUser.email,
          message: 'marked request as completed',
          actionType: { connect: { id: 11 } },
        },
      },
     // the following lines causes the above error
      workers: {
        updateMany: {
          data: {
            projectId: existing.projectId,
          },
        },
      },
    },
  })
}

Expected behavior

Able to update all related records with no error.

Prisma information

schema.prisma other models are omitted for brevity.

datasource DS {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  binaryTargets   = "native"
  previewFeatures = ["orderByRelation"]
}

model Worker {
  id               Int              @id @default(autoincrement())
  name             String           @unique
  employeeNumber   String?
  socsoNumber      String?
  mobilePhone      String?
  remark           String?
  birthdate        DateTime?
  arrivalDate      DateTime?
  isManager        WorkerManager?   @relation("isManager")
  skills           Skill[]
  permits          Permit[]
  passports        Passport[]
  cidbGreenCards   CidbGreenCard[]
  workerRequests   WorkerRequest[]
  workerReleases   WorkerRelease[]
  cidbCompetencies CidbCompetency[]
  nationality      Country          @relation(fields: [nationalityId], references: [id])
  nationalityId    Int
  jobTitle         JobTitle         @relation(fields: [jobTitleId], references: [id])
  jobTitleId       Int
  project          Project?         @relation(fields: [projectId], references: [id])
  projectId        Int?
  employer         Employer         @relation(fields: [employerId], references: [id])
  employerId       Int
  manager          WorkerManager    @relation(fields: [managerId], references: [id])
  managerId        Int
  status           WorkerStatus     @relation(fields: [statusId], references: [id])
  statusId         Int
  beneficiary      Beneficiary?     @relation(fields: [beneficiaryId], references: [id])
  beneficiaryId    Int?
  createdBy        String
  createdAt        DateTime         @default(now())
  updatedBy        String
  updatedAt        DateTime         @updatedAt
}

model WorkerRequest {
  id              Int                   @id @default(autoincrement())
  startDate       DateTime
  endDate         DateTime?
  transferDate    DateTime?
  description     String?
  comment         String?
  jobTitle        JobTitle              @relation(fields: [jobTitleId], references: [id])
  jobTitleId      Int
  workersQuantity Int
  project         Project               @relation(fields: [projectId], references: [id])
  projectId       Int
  status          WorkerRequestStatus   @relation(fields: [statusId], references: [id])
  statusId        Int                   @default(1)
  skills          Skill[]
  workers         Worker[]
  actions         WorkerRequestAction[]
  createdBy       String
  createdAt       DateTime              @default(now())
  updatedBy       String
  updatedAt       DateTime              @updatedAt
  links           WorkerMovementLink[]
}

Environment & setup

  • OS: Windows Subsystem for Linux (Ubuntu-20.04)
  • Database: PostgreSQL
  • Node.js version: v14.16.1

Prisma Version

prisma               : 2.22.1
@prisma/client       : 2.22.1
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 60cc71d884972ab4e897f0277c4b84383dddaf6c
Studio               : 0.379.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
dakshshah96commented, Sep 17, 2021

Just got this error today. Saved, thanks to this issue. Can the error thrown by Prisma be better than just TypeError: value.map is not a function?

4reactions
pantharshit00commented, May 28, 2021

Pass an empty {} if you don’t want filtering but where is required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"TypeError: values.map is not a function" error occured when ...
Basically it's saying that you're trying to map over something that is not an Array.. If the code causing the problem is in...
Read more >
TypeError: map() is not a function in React | bobbyhadz
The "TypeError: map is not a function" occurs when we call the map() method on a value that is not an array. To...
Read more >
How To Fix object.map is not a function Error in JavaScript
To solve the object.map is not a function error, first figure out the shape of the data you are working with and then...
Read more >
JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
Read more >
How to Prevent the TypeError: Cannot Read Property Map of ...
In the second fetch, there is no country key in the data object, making it undefined . Calling the map function on it...
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