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

154
Views
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
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!