So, I’m working on an eCommerce application and my customer wants the ability to create categories and products…obviously. Now, lets say the client will have about 100 categories and 20,000 products.
The client needs the ability to create category properties that make sense for filtering….so, the category Hard Drives might have properties like:
- Capacity
- RPMs
- Form Factor
While the category Projectors might have properties like:
- Brightness
- Contrast Ratio
- Native Resolution
My question is how does one solve the problem of allowing custom properties to be created dynamically, but the ability to use those properties to search, filter and report on?
Creating a seperate table and object for each category isn’t possible since I have no idea what categories they will create (i.e. HardDriveProperties, ProjectorProperties).
I thought maybe I could create an extra column in the database and serialize the custom properties as JSON, but that would still require me to either create a specific properties object for each category to deserialize the JSON into or a generic list of ProductProperties….which I think could be pretty expensive to work with.
How are others solving this problem?
The Entity-Attribute-Value model (aka ‘open schema’) is one way to solve this problem.
The essence of the pattern is that you make columns into rows. Instead of
HardDrive(andProjector) tables that look like this:You have
Category,CategoryProperties, andCategoryPropertyValuestables: