On Wednesday, December 5, 2012 8:35:38 PM UTC+1, len wrote:
>
> I am new to web2py and have been going through the books and examples and 
> was wondering if when creating foreign-key if 'reference tablename' or 
> db.tablename is better to use.
> I looked in the 4th edition of the book and there is an example where a 
> table has multiple references to itself;
>
>     db.define_table('person',
>         Field('mother', 'reference person' ...
>         Field('father', 'reference person' ...
>
> and it indicates 'reference person' should be used in that case.  Which 
> should be used.
>
> small disclaimer: db.person exists only AFTER db.define_table('person', 
.....) so you can't use *db.person* in db.define_table('person', ....). 
'reference tablename' is the *recommended* way for ALL foreign keys
 

> Should length normally be supplied for field types that accept it?
>

length defaults to 512. If you don't set it explicitely, 512 will be used 
in most databases.
 

> When defining the type of field should you use type='string' or 'string' 
> or does it matter?
>

This is more a python question than a web2py one. there are named arguments 
and positional arguments. Current signature of the Field class is

        fieldname,
        type='string',
        length=None,
        default=DEFAULT,
        required=False,
        requires=DEFAULT,
        ondelete='CASCADE',
        notnull=False,
        unique=False,
        uploadfield=True,
        widget=None,
        label=None,
        comment=None,
        writable=True,
        readable=True,
        update=None,
        authorize=None,
        autodelete=False,
        represent=None,
        uploadfolder=None,
        uploadseparate=False,
        uploadfs=None,
        compute=None,
        custom_store=None,
        custom_retrieve=None,
        custom_retrieve_file_properties=None,
        custom_delete=None,
        filter_in = None,
        filter_out = None,
        custom_qualifier = None, 

So, if you do Field('something', 'string', 30) it will be the same as 
Field('something', type='string', length=30). It's just a matter of being 
explicit vs implicit.

-- 



Reply via email to