There are two tables, as follows:

db.define_table('A', Field('name'))

db.define_table('B', Field('name'), Field('id_from_table_a))

Also there are two applications.  One, called 'both_a_and_b', uses both 
tables and uses 'table_a_id'  as a foreign key in table B.  The other, 
called 'table_b_only' needs CRUD access to the information in table B, but 
it is not able to supply a value for 'id_from_table_a.'

I think because Postgres recognizes foreign key constraints, 'table_b_only' 
will not be able to create records in table B.  

What Is the right solution?

I can think of two.  First, create a third table, C, for all the data that 
'table_b_only' needs.  This table would not have the 'id_from_table_a' 
field.  The other application would need to write also to this table 
whenever it creates a record in table B.

A second possibility might be to define table B this way:
db.define_table('B', 
  Field('name') , 
  Field('id_from_table_a', requires= IS_EMPTY_OR(IS_IN_DB(db, 'A.id', ...)))
)

I would be grateful for any guidance,
Cliff Kachinske

Reply via email to