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), 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).
Tim Richardson, Director GrowthPath, Data-driven profit growth Mobile: +61 423 091 732 Office: +61 3 8678 1850 I tweet useful business & IT tips at growthpath_au GrowthPath Pty Ltd ABN 76 133 733 963 |
db = DAL(lazy_tables=True)
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/t5XrUYK3WDg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
db.define_table('b', Field('c'))
db.b.c.default = 'me'
db.b.c.requires = IS_IN_SET(('me', 'you'))
ATM, what I'm using on_define for is only database callbacks.