Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

683
Views
Cómo guardar varias tablas relacionadas entre sí con Prisma

Estoy trabajando en un proyecto de NestJS y tengo dos tablas ( TABLE_1 y TABLE_2 ), el esquema de TABLE_1 se ve así:

 model TABLE 1 { id String @id @default(uuid()) secondaryfield String @unique @map("secondary_field") @db.VarChar(12) table_2 Table_2[] }

Y la tabla 2:

 model TABLE 2 { id String @id @default(uuid()) table_1_id String @unique @map("secondary_field") @db.VarChar(12) table_1 Table_1 @relation(fields: [table_1_id], references: [id]) }

Dado que hay un FK en mi table_2 que depende de table_1 , y ambos se guardarán al mismo tiempo, ¿hay alguna forma que le permita a Prisma lidiar con esto y guardar múltiples campos (no solo dos como el ejemplo) con múltiples relaciones? ¿entre ellos? Estoy usando el método createMany() ya que generalmente guardo docenas de ellos al mismo tiempo.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes probar lo siguiente:

 prisma.table2.create({ data: { table1: { createMany: { data: [ { secondaryfield: 'table1-1', }, { secondaryfield: 'table1-2', }, ], } } } })

Más información aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!