I will bother with one last related question: *what about callback 
triggers?*
I'm defining them like this:

db.define_table('mytable', Field('field1'), Field('field2'))  # defines the 
table
from myglobals import myfunction  # imports global function
db.mytable._after_update.append(lambda s, r: myfunction(s, r))  # defines 
after update callback trigger

In this case, I guess lazy_tables=True wouldn't make sense, because I'm 
calling db.mytable so it triggers the definition of the table.

Is there a way of specifying callback triggers directly when calling 
define_table?




El jueves, 17 de marzo de 2016, 15:27:22 (UTC-3), Lisandro escribió:
>
> Oh I see! So I can define the virtual/method fields that way, and then it 
> does make sense to keep using lazy_tables. Completely missed that point.
>
> Thank you very much! 
> As always, web2py's community rocks. 
>
>
>
> El jueves, 17 de marzo de 2016, 14:59:35 (UTC-3), Anthony escribió:
>>
>> On Thursday, March 17, 2016 at 1:53:43 PM UTC-4, Lisandro wrote:
>>>
>>> Thank you very much for the quick answer.
>>>
>>> Your first comment made me think about the "lazy_tables" with the 
>>> definition of virtual method fields.
>>> If you say that doing db.tablename the table is no longer lazy, *then 
>>> it wouldn't make sense to use lazy_tables in a particular case where almost 
>>> each table has a virtual method field, am I right?*
>>>
>>> I mean, for example, if this is my model:
>>>
>>> db.define_table('first_table', Field('field1'), Field('field2'))
>>>
>>> db.first_table.field3 = Field.Method(lambda row: 'value for field3')
>>>
>>
>> This won't help with db.auth_user, which is defined automatically (though 
>> you can define it manually yourself if preferred), but you can simply do:
>>
>> db.define_table('first_table',
>>                 Field('field1'),
>>                 Field('field2'),
>>                 Field.Method('Field3', lambda row: 'value for field3'))
>>
>> Note, the first argument of Field.Method() and Field.Virtual() should 
>> always be the field name anyway, even if you are defining them like this:
>>
>> db.mytable.myfield = Field.Method('myfield', ...)
>>
>> There are particular cases where leaving the name out can lead to 
>> problems.
>>
>> Anthony
>>
>

-- 
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