putting
db.tablename.fieldname.requires = VALIDATOR()
doesn't do anything BUT if you have lazy_tables turned on, this syntax
would trigger the "unlazyification" of the table.
"Minus points" (the reverse concept of "bonus points") for
db.tablename.fieldname.requires = IS_IN_DB(db.othertable)
syntax that will trigger the "unlazyification" of both tables.
For all intents and purposes, a fixed validator that needs to be there in
every piece of code interacting with that field is better placed in the
table definition itself, i.e.
db.define_table('tablename', Field('fieldname', requires=VALIDATOR()))
in this way, when you enable lazy_tables the "unlazyification" would only
be triggered at the first access of db.tablename throughout your code.
Then again, if for some strict requirement you aren't able to define a
validator "inside" the table definition, again for the solely purposes of
lazy_tables, you should use the on_define argument
All of this is explained in the book at chapter 6 (the "on_define" is here
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#on_define>)
On Wednesday, April 15, 2015 at 7:50:34 PM UTC+2, Alex Glaros wrote:
>
> Here is a regular requires is_in_db statement:
>
>
> gov_org_query = (db.Organization.organizationPrimaryTypeID ==1)
>
> db.GovOrgJurisdiction.organizationID.requires =
> IS_IN_DB(db(gov_org_query), 'Organization.id',
> '%(organizationFullName)s',zero=T('choose one'))
>
>
> is it more efficient to put these two in the controller so they are called
> only when used?
>
> I don't understand if they would get executed needlessly if placed in the
> model if the function that needs them is not used for many sessions
>
> thanks
>
> Alex Glaros
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.