How to query/represent 1-to-many information in the list page
create users (id, name, ...)
create user_tags (id, user_id, tag_name)
user has 1 to many user_tags
Sample data - I would like the table to be rendered as
user1 tag1,tag2
user2 tag3
user3 tag1
user4
user5 tag5,tag6.tag7
In order to construct the above table, I would have to do the following to construct each row.
i.e.
select * from users;
for (User user : users) {
// select tag_name from user_tags where user_id = user.id
List<Tag> tags = fetchtags(user)
}
Is there a better way to fetch | cache tags for an user, so that it doesn't take a longer time to construct the above list of users.