PrismaP
Prisma14mo ago
7 replies
Jon Higger (He / Him)

CreateMany not allowing me to create nested M:N entities

I've got a situation where this query works:

await prisma.item.create({
  data: {
    order: 1,
    sectionId: "1",
    itemTags: {
      create: [
        {
          tagId: "1",
        },
      ],
    },
  },
});


But this doesn't:

await prisma.item.createMany({
  data: [
    {
      order: 1,
      sectionId: "1",
      itemTags: {
        create: [
          {
            tagId: "1",
          },
        ],
      },
    },
  ],
});



Right now my prisma schema looks sort of like this:

model Tag {
  ...stuff
  itemTags  ItemTag[]
}
model ItemTag {
  id        String   @default(cuid())
  itemId    String
  tagId     String
  item      Item     @relation(fields: [itemId], references: [id])
  tag       Tag      @relation(fields: [tagId], references: [id])

  @@id([itemId, tagId])
}
model Item {
  ...stuff
  itemTags  ItemTag[]
}
Was this page helpful?