I think you're right -- those attributes shouldn't trigger the lazy
definition. on_define would be more useful in case something expensive is
happening in defining one of the attributes. Also, if you define an
IS_IN_DB or IS_NOT_IN_DB that has a Set object as the first argument (as
the query will involve doing something like db.sometable.somefield ==
some_value, which would cause sometable to be defined).
Anthony
On Tuesday, July 22, 2014 10:01:33 PM UTC-4, Tim Richardson wrote:
>
> I'm trying to improve ch 6 in the book, DAL.
> The on_define parameter to define_table is not documented.
>
> This is my current text, but the example concerns me because it seems
> redundant to me. That is, until I found the example, I thought that adding
> such simple requires settings via Field definitions would still leave the
> table lazily defined.
>
> on_define
>
> on_define is a callback triggered when a lazy_table is instantiated,
> although it is called anyway if the table is not lazy. This allows
> dynamic changes to the table without losing the advantages of delayed
> instantiation.
>
> Example:
>
> db = DAL(lazy_tables=True)
> db.define_table('person',Field('name'),Field('age','integer'),
> on_define=lambda table: [
> table.name.set_attributes(requires=IS_NOT_EMPTY(),default=''),
>
> table.age.set_attributes(requires=IS_INT_IN_RANGE(0,120),default=30),
>
>
>
>
>
--
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.