[web2py] Re: Postgres expers -- interesting design issue

2012-04-20 Thread Sundar
Cliff By adding the 'null' to the 'purchase_order_id' in the product_lots table, you automatically achieve it - that is, if the field is declared as Null, foreign key constraint is applicable only if it is non-null and a null value will automatically skip validation for foreign key. Another

[web2py] Re: Postgres expers -- interesting design issue

2012-04-20 Thread Cliff
Thank you, Sundar. I understand. This solution means I relinquish the foreign key constraint on the product_lots table. It does seem simpler than using another table for raw materials. No third alternative, I guess... On Friday, April 20, 2012 2:37:38 AM UTC-4, Sundar wrote: Cliff By

[web2py] Re: Postgres expers -- interesting design issue

2012-04-20 Thread Sundar
Not sure if 'relinquish' is the right word since the foreign constraint is going to be enforced if you enter a value for the PO. (May be my statement was a little confusing). Please see the example: Create Table t1(a int primary key) Create table t2 (b int primary key, ba null references

[web2py] Re: Postgres expers -- interesting design issue

2012-04-19 Thread nick name
I don't understand what you are trying to achieve, but whatever it is, you are doing it wrong; your model should be: db.define_table('A', Field('name')) db.define_table('B', Field('name'), Field('id_from_table_a', 'reference A')) # alternatively: # db.define_table('B', Field('name'),

[web2py] Re: Postgres expers -- interesting design issue

2012-04-19 Thread Cliff
nick, Thanks for the response. Here's a longer explanation. Two applications, one is purchasing, the other is production. Purchasing has two tables, purchase_orders and product_lots. It's a one-to-may relationship; a purchase order can have many product lots. So we get: