I have a Post and PostComment model. They are in a HasMany relationship, as the picture suggests. ER diagram
I need to return all posts, and, the latest comment for each post, paginated.
The problem is that I need also to do a search on the "post_comments" table. Something like "get all posts from a specific user, ...". So I decided to use the JOIN.
My problem is that with JOIN I do not receive only one entry per post, but rather as many post entries, as there are comments in the related table.
I tried to group the result by "post_id", but some critics said that this is not good. What would be the "proper approach " for this?