You could also conditionally define the virtual field only when you will need it (define it before executing the select query).
Anthony On Friday, October 18, 2013 9:07:34 AM UTC-4, Anthony wrote: > > > db.define_table('tableaa', Field('afield', 'string', required=True ), >> Field('bfield', 'string', required=True ), >> ) >> db.tableaa.virtfield = Field.Virtual( lambda row: XML("<strong>" + >> row.tableaa.afield + '</strong><br> ' + row.tableaa.bfield )) >> >> When this something is a virtual field, as is the case then the two >> fields it concatenates need to be in every query I select from that table >> or I get an error regardless of whether the virtual field is in the list of >> selected fileds or not. >> > > You could re-write the virtual field function so it doesn't fail when one > or both of the required fields are missing: > > def virtfield(row): > try: > return CAT(STRONG(row.tableaa.afield), BR(), STRONG(row.tableaa. > bfield)) > except: > return '' > > db.tableaa.virtfield = Field.Virtual(virtfield) > > Anthony > -- 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.