The first argument to IS_IN_DB can be either a DAL object (i.e., just "db") 
or a Set object (which is what you want). The second argument must be a 
field (either a field object or the name in 'tablename.fieldname' form) -- 
it cannot be a Query object, as you are using. So, you want:

IS_IN_DB(db(db.Organization.organizationPrimaryTypeID == 1), 
'Organization.id')

This is explained in the book 
<http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators>
.

You might also want to include db.Organization._format as the third 
argument, so the labels in the select element will be based on the "format" 
attribute of the Organization table.

Regarding your other initial attempts:

   - If you are going to use a lambda function as a validator, not that it 
   must take a Field object as its first argument and the value to be 
   validated as its second argument, and it must return a tuple, with the 
   (possibly transformed) value as the first element, and either None or an 
   error message as the second.
   - If you put IS_IN_DB in a list, you won't get a dropdown in forms. To 
   use additional validators with IS_IN_DB but still get the dropdown, instead 
   of putting it in a list, pass the additional validators as its "_and" 
   argument (also documented in the book).

Anthony

On Wednesday, September 16, 2015 at 8:34:32 PM UTC-4, Alex Glaros wrote:
>
> okay, I get similar error no matter what table or fields used.
>
> Is this syntax wrong?
>
> Field('organizationID','reference Organization', requires = IS_IN_DB(db, 
> db.Organization.organizationPrimaryTypeID == 1)), 
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to