Ah, stupid me. Thanks.
On Jan 31, 8:42 am, Anthony <abasta...@gmail.com> wrote: > Not sure if this is the problem, but it should be: > > IS_IN_DB(db, ...) > > not > > IS_IN_DB(db.A, ...) > > Anthony > > > > > > > > On Tuesday, January 31, 2012 9:11:48 AM UTC-5, Rick Ree wrote: > > > I've run into a basic problem that I can't seem to figure out: > > > db.define_table('A', Field('name'), format='%(name)s') > > db.define_table( > > 'B', > > Field('number'), > > Field('name', db.A, > > requires=IS_EMPTY_OR(IS_IN_DB(db.A,'A.id','%(name)s'))) > > ) > > > All I want to do is allow db.B.name to be empty. As far as I can tell > > the requires= for db.B.name is the accepted way to do this - if I > > leave it out, SQLFORM validation will throw an error. But trying to > > insert a record into db.B using SQLFORM raises this ticket: > > > Traceback (most recent call last): > > File "/home/rree/web2py-1.99.4/gluon/restricted.py", line 204, in > > restricted > > exec ccode in environment > > File "/home/rree/web2py-1.99.4/applications/welcome/controllers/ > > appadmin.py", line 433, in <module> > > File "/home/rree/web2py-1.99.4/gluon/globals.py", line 172, in > > <lambda> > > self._caller = lambda f: f() > > File "/home/rree/web2py-1.99.4/applications/welcome/controllers/ > > appadmin.py", line 127, in insert > > form = SQLFORM(db[table], ignore_rw=ignore_rw) > > File "/home/rree/web2py-1.99.4/gluon/sqlhtml.py", line 862, in > > __init__ > > inp = self.widgets.options.widget(field, default) > > File "/home/rree/web2py-1.99.4/gluon/sqlhtml.py", line 215, in > > widget > > options = requires[0].options() > > File "/home/rree/web2py-1.99.4/gluon/validators.py", line 2453, in > > _options > > options = self.other.options() > > File "/home/rree/web2py-1.99.4/gluon/validators.py", line 460, in > > options > > self.build_set() > > File "/home/rree/web2py-1.99.4/gluon/validators.py", line 443, in > > build_set > > fields = [self.dbset.db[self.ktable][k] for k in self.fields] > > File "/home/rree/web2py-1.99.4/gluon/dal.py", line 5542, in > > __getattr__ > > return self[key] > > File "/home/rree/web2py-1.99.4/gluon/dal.py", line 5482, in > > __getitem__ > > return dict.__getitem__(self, str(key)) > > KeyError: 'db' > > > Am I missing something? > > > Thanks > > -Rick