Question - and I'm afraid I know the answer. Let'...
# orm-help
m
Question - and I'm afraid I know the answer. Let's say that I'm creating a bunch of contacts, and each contact may have attributes that belong in related tables (contact HAS MANY emails, contact HAS MANY tags...) I was hoping that I could create the contacts AND their related records in createMany...
Copy code
prisma.contact.createMany({
  data: [
    {
      ...contact attrs,
      tags: {
        create: {...}
      }
    }
  ]
})
and so forth. But it looks like that's only possible for create. so I'm guessing my two options are: 1. CreateMany the contacts, then match them back up with the input to get the right ID on the related records 2. Create (single) each contact with its related records in place. Maybe in a transaction/ Promise all. Am I missing something - are those my two options?
✅ 1
a
Yep, no nested creates inside createMany. So either create serially, or simply use createMany for each of the records (with predefined IDs) and use prisma transactions to create the whole.
n
Hi Michael 👋 You cannot nest
create
,
createMany
,
connect
,
connectOrCreate
inside a top-level
createMany
But you can nest a
createMany
inside a
create
query. I would suggest creating a single record with its related records.
m
@Nurul Yes - that's fine - except I have many single records that need to be created - it could even be upwards of many hundreds of contacts (the top level) added at once. I ended up generating the ID for the contact record myself and then passing it into the contact record and its related records.
👍 1