0
I’m developing a database for a local travel agency:
I need to pick up all the passengers and store them in one entity Viagem
, so that in the "passengers" field of the latter would be of the JSON type, in which would be a array of foreign passenger keys.
Example:
-- Retorna um array de ids de passageiros da última viagem criada.
SELECT passageiros FROM viagens
ORDER BY created_at DESC
LIMIT 1;
-- retorno
+---------------+
| passageiros |
+---------------+
| [1,2,3,4,5,6] |
+---------------+
The question is: do you think it’s a good store like this? After all, when you need to add the id on the trip, just use the function JSON_MERGE_PRESERVE()
of Mariadb, which would preserve the others ids, and add the next one at the bottom of the list. And when I needed to research the passengers of the trip, all I had to do was make an algorithm that looked up the ids contained in this array.
Is a good?
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero