jeudi 1 mars 2018

Dynamic child properties

So I have need to have an architecture in place that allows for an object to have multiple child objects and those child objects have different dynamic properties. Take this for instance:

restaurants table
-----------------
id int primary_key unique not null
name varchar(50) not null

restaurants_equipment table
---------------------------
restaurant_id int
equipment_id int
??? JSON values of properties ???

equipment table
---------------
id int primary_key unique not null
name varchar(50) not null
??? JSON of available properties per equipment ???

So imagine, if you will and for simplicity sake, that there are 2 restaurant records, and 3 equipment records. The three records in the table are "Oven, Microwave, and Stove". Oven has properties that need to be stored of max_temperature (integer), racks_space (array of rack sizes). Microwave has properties of max_timer (integer), popcorn_setting (boolean). Stove has properties of num_of_tops (integer), stove_type (integer).

As you can see, each piece of equipment can have any type of dynamic properties that also need to be tied to the restaurant with the values they may have for that piece of equipment.

So, my question is what is the best approach to have dynamic properties per record in equipment and those values to be stored appropriately in a relationship between the equipment and particular restaurant AND be able handle constraints with this properties for user input (ie store constraint information, as well, etc?)?

Aucun commentaire:

Enregistrer un commentaire