I am getting an exception raised when I combine virtual fields and aliases.
Here is an example that produces the error. The example may not have
practical use. It is used for illustration only.
# In models/db.py
db.define_table('person',
Field('first_name'),
Field('last_name'))
db.define_table('couple',
Field('husband_id',
requires=IS_IN_DB(db, 'person.id', '%(first_name)s')),
Field('wife_id',
requires=IS_IN_DB(db, 'person.id', '%(first_name)s')
))
class PersonVirtFields(object):
def name(self):
return "%s %s" % (self.person.first_name, self.person.last_name)
db.person.virtualfields.append(PersonVirtFields())
# In controller
def index():
husband = db.person.with_alias('husband')
rows = db(db.couple.id>0).select( husband.first_name,
left=husband.on(husband.id==db.couple.husband_id))
return dict(rows=rows)
The exception is:
AttributeError: 'PersonVirtFields' object has no attribute 'person'
I can avoid the exception if I change the line in the PersonVirtFields name
method to:
return "%s %s" % (self.husband.first_name, self.husband.last_name)
The virtual class appears to be receiving the table name as per its alias.
Is this a bug or is that expected behaviour?
Regards,
Jim Karsten