I'm creating an api in ruby on rails, I have a couple tables events, artists, and countries, events has artist_id which is a foreign key to the id field in artists. Events also has country_id, which is a foreign key to country id field. When a user asks my api for /events/artist/:artist_id, I want to return json results in the form of
[
{
"id":1,
"type":"festival",
"artist":{
"id":1,
"name":"doesnt matter"
},
"country":{
"id":1,
"name":"cambodia"
}
]
I'm unsure however how to include nested objects in my json response, would I do multiple queries and some how inject them into my json response? I am sure there are better ways to set up my database for this as well and I'm open to suggestions but an event can only have one artist and be in one country, though countries can have multiple events. The core of my issue is not the database though, I cant find any information how to nest queries in my response.(Which is I think what I need to do) ruby on rails - 6.0.2, ruby 2.7.1