I have a table with user data, where most of the columns can be public or private (so it will be shown or not on the app) and every user can decide which fields to hide. So far I had a couple of ideas.
Extra field for each field
My first idea was to just add a boolean to each fiend to mark if the previos column was public.
---------------------------------------------------------------------------------------
| user_id | user_data_1 | user_data_public_1 | user_data_2 | user_data_public_2 | ... |
|---------|-------------|--------------------|-------------|--------------------|-----|
| int | string | boolean | int | boolean | ... |
---------------------------------------------------------------------------------------
In this case I have to use IF(user_data_public_1, user_data_1, NULL)
on the SELECT
query.
Related table to mark public fields
Another idea was to have the table with the fields and a related table with to mark the public fields:
---------------------------------------
| user_id | user_data_1 | user_data_2 |
|---------|-------------|-------------|
| int | string | string |
---------------------------------------
---------------------------------
| user_id | filed_name | public |
|---------|------------|--------|
| int | string | string |
---------------------------------
In this case I'd need to do the JOIN
and check if the field is public on the related table.
I don't like so much any of the solutions, so is there some elegant and hopefully efficient solution to solve this type of design.
Thanks in advance.