How to use createMany with relations without encountering the “Argument data: Invalid value provided” error?

when using the createMany function with relations, I encounter the “Argument data: Invalid value provided” error.

I have referred to the documentation, which states that only the create function can be used for relations
You cannot create or connect relations – you cannot nest create, createMany, connect, connectOrCreate inside a top-level createMany
(source : https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#createmany)

but I have not been able to determine the correct syntax for passing relations to the create function.

I attempted to use the createMany function with relations in Prisma by providing an array of data objects with nested relation fields. I expected the function to successfully create multiple records along with their associated relations. However, I encountered the “Argument data: Invalid value provided” error, preventing the creation of records with nested relations.


// schema.prisma
model Language {
  id        Int      @id @default(autoincrement())
  name      String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  pastes Paste[] @relation("paste_language")
  aliases LanguageAlias[] @relation("language_alias")
  extensions LanguageExtension[] @relation("language_extension")

  @@map("language")
}

model LanguageAlias {
  id         Int       @id @default(autoincrement())
  alias      String
  languageId Int
  language   Language  @relation("language_alias", fields: [languageId], references: [id])
  @@map("language_alias")
}

model LanguageExtension {
  id         Int       @id @default(autoincrement())
  extension  String
  languageId Int
  language   Language  @relation("language_extension", fields: [languageId], references: [id])
  @@map("language_extension")
}

// seedLanguage.js
try {
  await prisma.language.createMany({
    data: [
      {
        name: "JavaScript",
        aliases: {
          create: [{ alias: "JS" }, { alias: "ECMAScript" }],
        },
        extensions: {
          create: [{ extension: ".js" }, { extension: ".mjs" }],
        },
      },
      {
        name: "Python",
        aliases: {
          create: [{ alias: "Py" }],
        },
        extensions: {
          create: [{ extension: ".py" }],
        },
      },
    ],
  });
} catch (e) {
  e.functionName = "seedLanguage";
  throw e;
}