iamjaredsimpson's avatar

Database table setup for storing product attributes

I'm building an ecommerce website that can have a bunch of products of varying categories. I'm trying to come up with a way to store different product attributes. My definition of attributes would be the type of details you see in the amazon sidebar when searching for products.

An example would be something like a hard drive has different manufactures, price points, storage sizes...while a video games might have different platforms, price points, number of players, minimum requirements if on pc, etc.

Right now I have it set up as a glorified multilevel category using the Baum package. Basically the idea is that the first level can be the category of product (like video games), then the next level would be all the titles of attributes that category can have (platforms, number of players), and then the next level under each of those would be all of the possible options (xbox one, ps4, switch, pc). Then I have a pivot table linking the product with each of the appropriate attributes that it belongs to.

Is this a decent approach?

Or would it be better to use polymorphic many to many relationships? I feel like that would become kind of confusing and my database would end up with a ton of tables for each set of attributes. I also don't want to do a regular many to many table because I'd like to be able to generate the appropriate attributes for each category with a single query.

0 likes
0 replies

Please or to participate in this conversation.