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

329
Views
¿Cómo usar JSON Array como clave externa para la misma tabla? (Secuela + Postgres)

tengo la siguiente tabla:

identificación nombre hermanos
1 John [3, 4]
2 ben []
3 María [1, 4]
4 Pedro [1, 3]

¿Cómo establecer una relación en la que pueda obtener todos los datos de los hermanos en una sola consulta en un solo registro? la columna de los hermanos está usando el tipo de matriz de Postgres.

En este momento estoy usando 2 consultas, 1 para obtener a John, y luego consulto nuevamente para obtener información de los hermanos según las identificaciones de sus hermanos.

Encontré lo siguiente en Sequelize Docs:

Sequelize admite relaciones autorreferenciales de muchos a muchos, de forma intuitiva:

 Person.belongsToMany(Person, { as: 'Children', through: 'PersonChildren' }) // This will create the table PersonChildren which stores the ids of the objects.

Pero no pude hacerlo funcionar con:

 People.belongsToMany(People, { as: 'Brothers', through: 'peopleBrothers', foreignKey: 'brothers' })

Se puede hacer esto?

about 4 years ago · Juan Pablo Isaza
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!