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

319
Views
In TypeORM, how do I get raw data in a structurerd format?

This is my model. There's a many-to-many relationship between user and post.

ER Diagram

My current querybuilder:

getRepository(Post)
    .createQueryBuilder("post")
    .innerJoinAndSelect("post.creator", "user")
    .select(["post.id", "post.content", "post.createdAt", "user.id", "user.username", "user.avatar"])
    .orderBy("post.createdAt", "DESC")

Results:

[{
    id: 18,
    content: "I'm Ana.",
    createdAt: "2021-11-09T04:06:48.931Z",
    creator: {
        id: 31,
        username: "ana",
        avatar: "https://avatars.dicebear.com/api/female/ana.svg"
    }
}]

I want to add another field "liked", a boolean value telling me if the logged-in user has liked the post. I could use getRawMany, but the json would be completely flat, and I don't want to destroy the current API format. Is there a way I can get the best of both worlds?

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!