In my application, I need to capture settings values for a certain entity called "Thing". There is a default value for each setting but the user can override these if needed. I have the following tables to capture the information:
Things table
ID | Name
-----------
1 | Thing1
2 | Thing2
ThingSettingsDescriptions Table
ID | SettingDescription | Default
---------------------------------------
1 | Colour | Blue
2 | Size | Medium
3 | Temperature | Hot
ThingSettingsValues Table
ID | ThingID | ThingSettingsID | Value
---------------------------------------------
1 | 1 | 1 | Blue
2 | 1 | 2 | Medium
3 | 1 | 3 | Hot
4 | 2 | 1 | Blue
5 | 2 | 2 | Medium
6 | 2 | 3 | Hot
In sample data above Thing1 and Thing2 have default settings - hence the entries in the ThingSettingsValues are repeated for each thing. This seems a bit inefficient to me.
Is there a way to avoid repeating these default values for each thing?
The closest question I've found to mine is this but it's not quite what I'm looking for.
Another option I thought of would be to only store non default values in the ThingSettingsValues table. This means in the application when the settings for a thing are required, we check the ThingSettingsValues table, if it contains no entries for that thing, read the default values from the ThingSettingsDescriptions table then use these default settings values instead. This would work but means the database does not explicitly capture where to get settings values for a thing if there are no entries in the ThingSettingsValues table.
Thanks
Aucun commentaire:
Enregistrer un commentaire