Here are my 2 tables defintion:
db.define_table('question',
Field('category_id',db.category),
Field('content'),
Field('number_of_options','integer'),
Field('has_options_detail','boolean',default=False)) ## Has or not has detail for each option
db.define_table('options_detail', ## This table only for options that have detail explanation
Field('question_id',db.question),
Field('serial'), ## Option ordering
Field('detail')) ## Detail explanation of option
How can I restrict that: db.options_detail.question_id must belong to questions that have field “has_options_detail == True”
Thanks in advance!
This should do it:
Note, the IS_IN_DB validator can take a DAL Set object as the first argument (see here), which enables you to filter the referenced table based on any criteria.
(You could also specify the above
requiresargument directly in theField()declaration.)