I would like to receive a data object country. An object country has the following attributes (id, continent_id, language_id).
Table countries {
id, name, continent_id, language_id
}
Table continents {
id, name
}
Table languages {
id, name
}
Instead of getting a DataObject containing only the continent_id
and language_id
, I want to get the name of the continent and the language. Like that:
{
id: 1,
name: Germany,
continent_id: 1,
language_id: 1,
continent: "europe", // new field
language: "german" // new field
}
How can I achieve this?
2
Answers
I found a simple solution for my case. Maybe not the smartest but it works. There are probably better solutions. I don't know what influence the size of the data set will have on the performance. I still have to test this.
you need to join the two additional tables to the man countries
If every country has only one language, this will be enough to
INNER JOIN
them.with multiply languages, you need to
GROUP BY
and useGROUP_CONCAT
or the languagesIf a country has multiple languages