On Wednesday 12 October 2005 06:12 am, Liquid wrote:> Hi everyone.
howdy.
> I''m looking to implement a product structure that behaves
basically like a
> bill of materials in that each product can exist in the bill of materials
> of any other product.
>
> Say there is a table
>
> Product
> id
> name
> unit
>
> I would like the entries in the product table to behave as assemblies and
> components. ie. each product can in fact be an assembly or a component in
> an assembly. The trick is that each product can contain many components,
> sub-assemblies, many instances of any given component and itself can exist
> in many assemblies.
>
> My initial thought before I thought to have many instances of a component
> in the assembly is to have the following table
>
> product_products
> assembly_id
> component_id
> qty
>
> where the assembly_id and the component_id are foreign keys to the product
> table. But after thinking about the many instances of a component
I''m not
> really sure how to go about it.
>
> Any help would be appreciated. Especially anyone who can interperate what
> I''ve tried to describe ;)
>
> Cheers
> Dan
forgive me if I am wrong, I just started with ruby and RoR last week, but
I''ve
been reading the very fine Agile Web Development with Rails book from the
Pragmatic Programmers. :)
You could have a table kinda like this:
table: product
id: int
product_name: text
is_assembly: bool
then establish a many_to_many relationship with the condition that the parent
has to be an assembly (in the is_assembly field), and those relationships
would be stored in a join table product_products
I don''t have my book with me here at work, and I don''t know
enough about rails
to rattle off a class definition for this, but if you follow what I''m
saying...
basically, say let''s have a chair.
each chair has a back, a seat, and legs
the back is an assembly of 2 back_side pieces and 3 back_cross parts
the seat is not an assembly
the legs are an assembly of 4 leg_legs and 4 leg_cross pieces
so you have items in your products table kinda like this (hopefully the tabs
come across)
id product is_assembly
1 chair 1
2 back 1
3 seat
4 legs 1
5 leg_legs
6 leg_cross
7 back_side
8 back_cross
then in your product_products, something like this (again, tabs)
product_parent product_child qty
1 2 1
1 3 1
1 4 1
2 7 2
2 8 3
4 5 4
4 6 4
I hope this is what you mean, and what I''ve said makes sense.
I''ll check back on this after I get home and see if you understood what
I
said, and if this is what you''re looking for, I''ll fire out
the class
definitions real quick (practice is good, y''know ;)
-Jeremy
--
Jeremy Kitchen ++ kitchen-RA8HwDor7flnDGu+y90WmgC/G2K4zDHf@public.gmane.org
In the beginning was The Word and The Word was Content-type: text/plain
-- The Word of Bob.
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails