Richard
Thanks for the clarification. My solution was only form-level, without
regard for foreign key relations.
-Jim
On 11/15/2011 8:52 AM, Richard Vézina wrote:
By default web2py will only work with id (I think) except if you go
with legacy feature (see book about that). So by default with what you
propose both will pass the id to your FK field of your foreigh table.
But in one case user will see name of person only and in the other
case name and id of the person in the dropdown.
Jim is right if you want to store the name you will use :
db.tableName.name.requires = IS_IN_DB(db, 'person.name
<http://person.name/>', '%(name)s', zero='choose one')
But this is only a form level constrain... You will maybe want
implement constrain at DB level too.
Note that your fk field will be : Field('name', 'string'), instead of
Field('person_id', db.person),
With "name" there will be no foreign key constrain create by web2py by
default, so you have different option to enforce it at db level
(manually by creating constain at db level, or raw SQL from web2py).
Also, you will need your "name" records to be unique, if there is more
than one Richard, Annet or Jim it will be problematic depending of
your needs. :)
I suspect that you want to use "name" because you just want name show
in the dropbox and in the select... If it's true you should read more
about .represent() it is the complement of .requires().
Richard
On Tue, Nov 15, 2011 at 5:20 AM, annet <[email protected]
<mailto:[email protected]>> wrote:
To represent referenced records in select/option drop-downs the web2py
book gives two options:
db.define_table('person', Field('name'), format='%(name)s')
db.define_table('person', Field('name'), format='%(name)s %(id)s')
In an application I need a drop down that inserts a name as a value
and I need a drop down that inserts an id as a value. Do I use the
first option for the former and the second option for the latter?
Kind regards,
Annet.