Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
A type table that references various different tables based on targetId and targetType

Been stuck on this annoying problem with index and foreign key problems.

Lets say you have 2 models

model Follows {
 id    BigInt

 followerId  BigInt @map("follower_id")
 followingId BigInt @map("following_id")

 follower  Users @relation("following", fields: [followerId], references: [id])
 following Users @relation("follower", fields: [followingId], references: [id])

 posts Posts @relation(fields: [followingId], references: [authorId], map: "follows_following_posts_fkey")
}

Now the Posts model

model Posts {
 id BigInt

 authorId BigInt
 author   Users @relation(field: [authorId], references: [id])

 follows Follows[]
}

When I ultimately query Follows, include the Following Users, i also want to be able to fetch the posts of those following users. So the relation that the followingId of any user references to the posts model authorId which ultimately should give me back all the posts the following user has made?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda