thank you, very helpful.
On Thursday, March 21, 2013 11:57:40 PM UTC+3:30, Niphlod wrote:
>
> just to clear out doubts.....
> a field 'reference sometable' gets:
> - a foreign key to the id of sometable
> - a validator that by default builds up on the format argument of
> sometable
>
> you CAN'T have a foreign key to a table and have the requires parameter
> with is_in_db() building a string value.
> So, if you want the 'origin' field to store the integer that is a pointer
> to the countries.id table, while retaining the country_name while
> representing it in the dropdown, you should do
>
> db.define_table('countries',
> Field('country_name'),
> format='%(country_name)s'
> )
> db.define_table('testing',
> Field('origin','reference countries')
>
> )
>
> or
>
> db.define_table('countries',
> Field('country_name'),
> )
> db.define_table('testing',
> Field('origin','reference countries',requires=IS_IN_DB(
> db,'countries.id', '%(country_name)s',error_message='Choose origin
> country'))
> )
>
> if you want testing.origin to be a string holding country names (so, not a
> reference), with the dropdown showing the countries you have in the
> countries table
>
> db.define_table('countries',
> Field('country_name'),
> )
> db.define_table('testing',
> Field('origin',requires=IS_IN_DB(
> db,'countries.country_name',error_message='Choose origin country'))
> )
>
>
>
> tl;dr your "mix and match" doesn't specify what you want. Field type
> "trumps" the requires parameter on a database level.
>
> On Thursday, March 21, 2013 9:02:20 PM UTC+1, Cliff Kachinske wrote:
>>
>> The syntax may be correct per the manual, but IS_IN_DB tells Postgres to
>> create a foreign key constraint on the field. If you look at the tables
>> with psql or pgadmin you will see this is so.
>>
>> A foreign key constraint is always on the primary key of the foreign
>> table. It has to be this way to guarantee uniqueness.
>>
>> This will work:
>>
>> countries = [r.countryname for r in
>> db(somequery).select(db.countries.countryname)]
>>
>> db.testing.origin.requires = IS_IN_SET(countries)
>>
>>
>>
>> On Thursday, March 21, 2013 3:36:51 PM UTC-4, Alan Etkin wrote:
>>>
>>> > there is no string validator, i just use IS_IN_DB to create drop down
>>> widget
>>>
>>> Yes, sorry, I checked the api and it seems you are using the correct
>>> syntax.
>>>
>>> Does it work using IS_IN_DB (db, db.countries.country_name) instead?
>>>
>>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.