I’ve been mulling over a question of how best to organise the model/data for a certain specific kind of problem. I wonder if there are any good design patterns out there for this that I don’t know of.
Say, a user has several settings, and each setting has the same 2 or 3 attributes related to it:
We want to be able to ask at any given moment if the user has the given opt-in, and if necessary look up the reason for the opt-in.
On the one hand, the repetition in one dimension seems to point towards a single model/table in a
belongs_to relation with users, for example called
reason columns. However, this would mean a structural ambiguity: since there can in principle be an indeterminate number of settings for the given user, they may have an
opt_in for the given setting, or they may just not have the setting at all. At the interface level this leads to various related conundrums.
On the other hand, the fact that we want to know unambiguously about a definite set of settings seems to point towards a model that represents all settings in a single instance/row, so, say,
Settings, which has these as attributes:
… but the latter seems like a horrible kludge.
I flip-flop between these two seemingly unsatisfactory solutions. Is there a better 3rd option?