>
> I am referring to this type of code (from the book):
>
> db.define_table('person',
>     Field('uuid', length=64, default=lambda:str(uuid.uuid4())),
>
>     Field('modified_on', 'datetime', default=now),
>
>     Field('name'),
>     format='%(name)s')
>
> db.define_table('dog',
>     Field('uuid', length=64, default=lambda:str(uuid.uuid4())),
>
>     Field('modified_on', 'datetime', default=now),
>
>     Field('owner', length=64),
>
>     Field('name'),
>     format='%(name)s')
>
> db.dog.owner.requires = IS_IN_DB(db,'person.uuid','%(name)s')
>
>
Doing db.dog triggers the table to be defined, so to avoid that, just move 
the requires into the Field definition:

Field('owner', length=64, requires=IS_IN_DB(db,'person.uuid','%(name)s'))


if not db(db.person.id).count():
>
>     id = uuid.uuid4()
>     db.person.insert(name="Massimo", uuid=id)
>
>     db.dog.insert(owner=id, name="Snoopy")
>
>
Of course, the above code would trigger the table definition as well.

Anthony

-- 



Reply via email to