I have a Wine entity which is related to a country in a one to many relation (one country - many wines)
I can think of two ways to represent this in a json web service:
One is just including the whole country in a json
{
id: 76,
code: "FR",
name: "France"
}
{
id: 79,
name: "Bordeaux",
country: {
id: 76,
code: "FR",
name: "France"
},
year: "2005"
}
the other is including each country property to the same level, with a prefix
{
id: 79,
name: "Bordeaux",
countryId: 76,
countrCode: "FR",
countryName: "France"
year: "2005"
}
In any case, when updating or creating a new wine, I will just save the country id, I won't allow to modify a country from the endpoint of wines
The second approach would be easier to implement (I would have a join view on the db, and the serializer would just transform every field to json), but I think the first one is more elegant
Just wanted to know if there's any standard for this kind of situation and in case there isn't what is the more common approach...
ps: I don't mean to start a debate on the "restfullness" of the solution, just looking for a smart an simple way to handle this relation...