There are two distinctions here. First:

Field('owner', db.person)

is equivalent to:

Field('owner', 'reference person')

However, the latter is generally preferred because if you are using lazy 
table definitions, the former method triggers the full definition of 
db.person, so you lose the benefit of the lazy definition.

Second:

db.dog.owner.requires = IS_IN_DB(db, 'person.id', '%(name)s')

is equivalent to:

Field('owner', 'reference person', requires=IS_IN_DB(db, 'person.id', 
'%(name)s'))

Again, though, the latter is preferable in the case of lazy tables because 
the former will trigger the full db.dog table definition. Of course, as 
Massimo pointed out, neither of the above are really necessary if you 
specify the "format" argument in the db.person table definition, as that 
will result in a default validator equivalent to the above.

Anthony

On Friday, August 30, 2013 12:51:41 AM UTC-7, Mirko wrote:
>
> Hi all,
> I am really new to web2py and I find this python framework really exciting.
>
> I am currently reading the whole online book chapter database validators, 
> and while I was reading at the example given, I was wondering if there is a 
> difference between this :
>
> db.define_table('person', Field('name', unique=True))
> db.define_table('dog', Field('name'), Field('owner', db.person))
> db.dog.owner.requires = IS_IN_DB(db, 'person.id', '%(name)s')
>
> and this :
>
> db.define_table('person', Field('name', unique=True), format='%(name)s')
> db.define_table('dog', Field('name'), Field('owner', type='reference 
> person', required=True))
>
> Thanks a lot,
>
> Mirko
>

-- 

--- 
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.

Reply via email to