Answer the question
In order to leave comments, you need to log in
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
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.
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question