U
U
user_of_toster2021-11-24 12:13:26
PostgreSQL
user_of_toster, 2021-11-24 12:13:26

Is it a bad idea to store oneToMany relationships in a json column?

The table has a large number of relationships with other tables, say, 6 oneToMany relationships, which, with each request to the backend, need to be parsed in the form:

name: "Name",
surname: "Surname",
relation1: [{id: 1}],
relation1: [{id: 2}],
relation1: [{id: 3}],
relation1: [{id: 4}],
relation1: [{id: 5}],
relation1: [{id: 6}],


You can implement your own table of the form table1id:table2id for each connection and join with each request. It is possible not to produce tables and make a json column in which all links will be stored.

The JSON option seems simpler, less code, fewer joins, but something tells you that you don't need to do this. Can you advise which is the best option?

UPD: database - postgresql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-11-24
@user_of_toster

What kind of database do you have? If this is a relational database, then in this way you destroy its concept) With this approach, you deprive yourself (and the database) of at least an automatic check for the existence of a record in the table you refer to (Foreign Key Constraint)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question