I think all the problems arise from the fact that you do: IS_IN_DB(db(db.opportunity.id==db.task.opportunity_id),...)
this is a join and you cannot do a JOIN in a validator because you are referencing one table, not the temp table result of a join. Parhaps this is what you want: db.task.opportunity_id.requires=IS_NULL_OR( IS_IN_DB(db,'opportunity.id',lambda opp: opp.oppty_main_id.name)) Mind that if you have any broken reference (like a NULL reference or a reference to a record that no longer exist opp.oppty_main_id.name will break. Also mind that this is very slow since it results in a select for every record in the SELECT/OPTION. I would recommend caching the records and their names and use IS_IN_SET instead of IS_IN_DB. Massimo On Jan 13, 8:00 am, Miguel Lopes <mig.e.lo...@gmail.com> wrote: > I have the following tables: task, opportunity, and oppty_main > With the following relations: > * task.opportunity_id->opportunity.id > * opportunity.oppty_main_id->oppty_main.id > > When updating a task I have a SELECT for the related opportunities: > > db.task.opportunity_id.requires=IS_NULL_OR( > IS_IN_DB(db(db.opportunity.id==db.task.opportunity_id), > 'opportunity.id')) > > The problem is how to get the representation to show the name of the > opportunity, which is at oppty_main.name! > Something like (doesn't work): > db.task.opportunity_id.requires=IS_NULL_OR( > IS_IN_DB(db(db.opportunity.id==db.task.opportunity_id), > 'opportunity.id', > '%(db.task.opportunity_id.oppty_main_id.name)s') > > Miguel
-- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.