This is my model. There's a many-to-many relationship between user and post.
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?