Hi, I have a somewhat complicated relationship question. I''ve been banging my head about this for some time and have given in and decided to ask the list :) Here''s what I''m trying to achieve: Products can have variants. For example, a t-shirt could come in small, medium and large, but also black, green and blue in the first two sizes, but only blue in large. Basically, these are individual products but I''d like to group them together so that they appear as variants of a parent product. I considered creating a Variants table but because each variant will have its own stock level and possibly its own price, the Variants table would have the same structure as Products, apart from a link back to the original Product. Would it be a good idea to have a "product_id" column in the Products table that links back to the parent product? In Rails, would I use a has_many_and_belongs_to relationship? Or should I use my own SQL to avoid confusing Rails? Thanks for any help that anyone can offer. -- Matthew Revell www.understated.co.uk
Matthew Revell wrote:> Hi, > > I have a somewhat complicated relationship question. I''ve been banging > my head about this for some time and have given in and decided to ask > the list :) > > Here''s what I''m trying to achieve: > > Products can have variants. For example, a t-shirt could come in > small, medium and large, but also black, green and blue in the first > two sizes, but only blue in large. Basically, these are individual > products but I''d like to group them together so that they appear as > variants of a parent product. > > I considered creating a Variants table but because each variant will > have its own stock level and possibly its own price, the Variants > table would have the same structure as Products, apart from a link > back to the original Product. > > Would it be a good idea to have a "product_id" column in the Products > table that links back to the parent product? In Rails, would I use a > has_many_and_belongs_to relationship? Or should I use my own SQL to > avoid confusing Rails?This might be an appropriate use for acts_as_tree... -- Alex
On 16/09/05, Alex Young <alex-qV/boFbD8Meu8LGVeLuP/g@public.gmane.org> wrote:> > Would it be a good idea to have a "product_id" column in the Products > > table that links back to the parent product? > > This might be an appropriate use for acts_as_tree...Thanks Alex. I''ll give that a try. -- Matthew Revell www.understated.co.uk
On Friday, September 16, 2005, at 6:38:36 AM, Matthew Revell wrote:> Products can have variants. For example, a t-shirt could come in > small, medium and large, but also black, green and blue in the first > two sizes, but only blue in large. Basically, these are individual > products but I''d like to group them together so that they appear as > variants of a parent product.The variant idea seems heavy to me as a design notion ... I might look to mutually-constrained options instead. Pick color, the available sizes changes to match, something like that ... Ron Jeffries www.XProgramming.com Wisdom begins when we discover the difference between "That makes no sense" and "I don''t understand". --Mary Doria Russell
On 16/09/05, Ron Jeffries <ronjeffries-HInyCGIudOg@public.gmane.org> wrote:> The variant idea seems heavy to me as a design notion ... I might > look to mutually-constrained options instead. Pick color, the > available sizes changes to match, something like that ...Thanks Ron. I''m going to consider a particular t-shirt or saucepan, or whatever, as a product group, with each variant being a product. To the customer, they''d see a t-shirt with options to buy in blue, black and green, as well as the various sizes. However, in the database each t-shirt variant would be an individual product record, sharing a common product group. -- Matthew Revell www.understated.co.uk
On Friday, September 16, 2005, at 10:02:19 AM, Matthew Revell wrote:> On 16/09/05, Ron Jeffries <ronjeffries-HInyCGIudOg@public.gmane.org> wrote:>> The variant idea seems heavy to me as a design notion ... I might >> look to mutually-constrained options instead. Pick color, the >> available sizes changes to match, something like that ...> Thanks Ron.> I''m going to consider a particular t-shirt or saucepan, or whatever, > as a product group, with each variant being a product. To the > customer, they''d see a t-shirt with options to buy in blue, black and > green, as well as the various sizes. However, in the database each > t-shirt variant would be an individual product record, sharing a > common product group.What advantages do you expect that approach will provide? Ron Jeffries www.XProgramming.com If you''re not throwing some gravel once in a while, you''re not using the whole road.