开发者

Ruby: JSON result for several depending tables

开发者 https://www.devze.com 2023-04-05 06:46 出处:网络
I am using working with the ruby blog example. So I have the tables posts, comments and tags. The posts table is related 1 to many comments and tags. This works great.

I am using working with the ruby blog example. So I have the tables posts, comments and tags. The posts table is related 1 to many comments and tags. This works great. - The point I don't get is how to get a single JSON response for a post at his depending records (tags and comments)? - How is the URL format to get all comments of the first post?

开发者_Python百科Thanks a lot, Vanessa


You would join the posts table with the comments table on post_id. Something like this:

 Select comments from comments, posts where posts.post_id = <id of post you want comments of> and posts.id = comments.post_id
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号