If we have a table full of products, but some products use slightly 
different fields, how should this be represented?

For example, if I sell clothing and furniture:

clothing and furniture share these fields:
 - price
 - description
 - stock
 - name

clothing have these special fields:
 - material/fabric
 - size

furniture have these special fields:
 - weight

Then, would this be a good way to handle it:

db.define_tables('product_fields', 
    Field('price', 'double'),
    Field('description', 'string'),
    Field('stock', 'integer),
    Field('name', 'string'))

db.define_tables('clothing_product',
    Field('material_fabric', 'string'),
    Field('size', 'string'),
    Field('product_field', 'reference product_fields'))

db.define_tables('furniture_product',
    Field('weight', 'double'),
    Field('product_field', 'reference product_fields'))

The other way I can think of would be to have only two tables; 
'clothing_product' and 'furniture_product' but have the shared fields be 
replicated in both tables.

If I use the first approach, how would I resolve these problems:

1) How do I query all products at once, both clothing and furniture(and 
more if I add different products in the future)?

2) Because the tables are split for the products (ie, a clothing product 
stores its data in 'clothing_product' and 'product_fields' tables), how do 
I build forms for both tables and save them in one html page? I looked 
here: http://www.web2py.com/book/default/chapter/07#Multiple-forms-per-page but 
that has two submit buttons that submit two independent forms.  The only 
solution I can think of is to build my forms manually and then grab the 
values to insert into the db.

3) if I want to associate a product with a category, how should this be 
linked? For example:

db.define_tables('categories',
       Field('category_name', 'string'))

db.define_tables('categories_and_products',    # Many to many relationship
       Field('category_id', 'reference categories'),
       Field('product_id', 'reference ???????'))      # what table should I 
reference here ???


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to