Saddly I can't use on_define for generic field define like so :

generic_fields_sign_id = \
    db.Table(db, 'generic_fields_sign_id',
             Field('sign_id', 'reference ref_sign',
                   # requires=IS_EMPTY_OR(IS_IN_DB(db(db.ref_sign.sign !=
'='), 'ref_sign.id', '%(sign)s')),
                   represent=lambda id, row: db.ref_sign(id).sign if id is
not None else T('N/A')
                   ),
             on_define=lambda table: [table.sign_id.set_attributes(
                 requires=IS_EMPTY_OR(IS_IN_DB(db(db.ref_sign.sign != '='),
'ref_sign.id', '%(sign)s')))]
             )

Will have to add it to every table that use generic_fields_sign_id...

Richard

On Wed, Mar 15, 2017 at 2:11 PM, Richard Vézina <ml.richard.vez...@gmail.com
> wrote:

> Yes, thanks, Simone cue me about the on_define argument... I wasn't know
> about that shame on me...
>
> :)
>
> Richard
>
> On Wed, Mar 15, 2017 at 1:48 PM, Anthony <abasta...@gmail.com> wrote:
>
>> On Wednesday, March 15, 2017 at 12:03:52 PM UTC-4, Richard wrote:
>>>
>>> We can even use a set inside an IS_IN_DB() requires inside model
>>> definition something like that prevent model from being lazy :
>>>
>>> db.define_table('tablename',
>>>                              Field('fk_id_field', 'reference
>>> othertable',
>>>                                        requires=IS_IN_DB(db(db.othert
>>> able.id > 0), 'othertable.id', '%(represent_field)s')
>>>                                        )
>>>                              )
>>>
>>> This is sad...
>>>
>>> I confirm that
>>>
>>> some_set = db(db.tablename.fieldname > 1)
>>>
>>> put in model outside of table definition prevent the table over which
>>> the set point from being lazy...
>>>
>>> And use of set inside IS_IN_DB() also prevent table from being lazy
>>>
>>
>> The point of lazy tables is that they are not fully defined until you 
>> *reference
>> *them (i.e., via db.mytable or db['mytable']). Of course, once you
>> reference them, they must be defined. If something like 
>> db.tablename.fieldname
>> > 1 would not trigger a table to be defined, what exactly would you
>> expect to trigger the definition?
>>
>> Anyway, the exact case you mention is covered by the on_define
>> <http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#on_define>
>> argument.
>>
>> If you want to improve performance related to model instantiation, you
>> should also consider conditional models as well as moving some model
>> definitions to modules.
>>
>> 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.
>>
>
>

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