M
M
magary42015-05-18 11:45:42
MySQL
magary4, 2015-05-18 11:45:42

Is it possible to replace the mysql join table with a field with a value in the form of a json array?

there are tables users, organizations
to link them many-to-many, you need the user2org table,
but what if you make the org column in users and write the array ["123","129"] there?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Valery Ryaboshapko, 2015-05-18
@valerium

You will lose the most interesting thing - the ability to use secondary keys, that is, to make quick and convenient selections.
More precisely, you can always use the built-in functions of MySQL, extract indexes from JSON and make another request, but you can imagine how much extra work this is for both the programmer and the server.
Another thing is if you regularly need a list of these indexes in the form of JSON for some purpose. Then you can either regularly overwrite this value with a trigger (but store it as an addition to the user2org table, and not instead of it), or write a tricky SQL query that will form this same JSON on the fly.

D
Dmitry Entelis, 2015-05-18
@DmitriyEntelis

The main rule: data denormalization must be done very clearly understanding what you are doing and why.
In the general case, storing links like this is not correct.

A
Andrey Mokhov, 2015-05-18
@mokhovcom

I wonder how you will hang up the secondary keys

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question