I am building a custom e-commmerce website in Rails.
In my data model products
have many SKU
s, and SKU
s have two properties: size and color.
I am wondering how I should add product images to this scheme.
One natural thing would be to put them on the product via a has_many
relationship. But if I do this it might be difficult to account for the fact that SKUs with different colors on the same product have different images.
If, on the other hand, I add product images to SKUs in a has_many
fashion then that will solve the color issue but raise a new one: within a color all SKUs have the same product images, regardless of their size.
I.e., product size doesn't affect a product's images but product color does.
Given that adding images to both products and SKUs has problems, perhaps I need to create a new model that captures the idea of UserFacingProductEntity
.
However this problem must have been solved before.