Thanks for reading, I hope this makes sense! I am trying to modify a bespoke CMS which gives different product options and lets you set various attributes based on combinations of those options. These are getting pulled from a mySQL database. For example, a t-shirt might have:
Colour Size
------ ----
Red Small
Red Medium
Blue Small
Blue Medium
Each colour and size would have a unique ID so red = 1, blue = 2 and small = 3, medium = 4. Colour and Size would each have a parent id, so colour = 1, size = 2.
At the moment I am storing a string in a database table in the database that identifies each combination (e.g. Red + small would be &1=1&2=3). This string then associates this combination of options with various attributes: price, stock code etc.
However the problem comes when we want to add a new option group to the mix, say sleeve length. At the moment this would mean having to go through the strings and changing them to also include the new option. This seems like a very inefficient and long-winded way to be doing this!
So (eventually!) my question is – is there a better way I can be doing this ? I need to ensure that there is no real limit on the number of option groups that can be added, as well as letting new option groups be added at any time.
Thanks in advance for your help.
Stuart
I would counter instead with asking you, why would you want to store that in the first place?
Cartesian products are a controller issue, not a domain model one. Your domain model (your database) should only care to keep the data in a normalized fashion (or as close as it’s feasible), let the database system do the joins as needed (
inner joinin sql), that’s what they’re optimized to do in the first place.