Still learning Go.
If I have a posts and comments table relationship in a mysqp/pg database eg
Post id, title
Comments id, post_id, comment
I'd like to have a json representation of this:
{
id: 1
title: "A blog post"
comments: [
{id: 1, comment: "This is comment 1"},
{id: 2, comment: "This is comment 2"}
]
}
I am able to grab the posts and show the json, just not the comments. I think I need to have an array of Comment structs in the Post struct. Just not sure how to tie it all together, particularly the scanning of the rows.
An example showing outputting json from a relationship like this would be great.