Massimiliano

Thanks for the reply.  Adding the fieldname didn't help, but pushed me to 
look again at the other post I'd referenced.  In it I missed adding the 
tablename to the row.id.  It should be row.workorder.id.  I made that 
change and now it works.

So, the solution is:

db.workorder.children = Field.Virtual('children', lambda row: db(db.
workorder.parent_workorder == row.workorder.id).select())

Thanks for the nudge Massimiliano!

-Jim


On Thursday, April 23, 2020 at 10:52:58 AM UTC-5, Massimiliano wrote:
>
> Maybe you miss fieldname:
>
> db.workorder.children = Field.Virtual(*fieldname*,  lambda row: db(db.
> workorder.parent_workorder == row.id).select())
>
>
> On Thursday, April 23, 2020 at 4:41:23 PM UTC+2, Jim S wrote:
>>
>> Given the following:
>>
>> from pydal import DAL
>> from pydal.objects import Field, FieldMethod, FieldVirtual
>> from qlf import util
>> ccfg = util.Config()
>>
>> db = DAL(ccfg.connect_db.dal_string, migrate=False, pool_size=5)
>> db.define_table('workorder',
>>                 Field('parent_workorder', 'reference workorder'),
>>                 Field('product'),
>>                 Field('quantity', 'decimal(11,2)'))
>>
>> db.workorder.children = Field.Virtual(lambda row: 
>> db(db.workorder.parent_workorder 
>> == row.id).select())
>>
>> wo = db.workorder(248222)
>> print(wo.children)
>>
>>
>> ...I get this when I run the code:
>>
>> Traceback (most recent call last):
>>   File 
>> "/home/jim/dev/miscellaneous/projects/scratch/virtual_fields_test.py", 
>> line 15, in <module>
>>     print(wo.children)
>>   File "/home/jim/.local/lib/python2.7/site-packages/pydal/objects.py", 
>> line 167, in __getattr__
>>     raise AttributeError
>> AttributeError
>>
>> What I'm trying to do is get a list of all child workorders for a 
>> specific workorder.
>>
>> I've also tried using Field.Method and calling as a function, but get an 
>> attribute error as well.
>>
>> Anyone have experience with Virtual Fields?  I haven't used them in or 
>> out of web2py yet but am interested.  Basically, I'm trying to reproduce 
>> the 'backref' behavior from SQLAlchemy.
>>
>> Thanks for any help
>>
>> -Jim
>>
>>

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/736742c2-6b07-4559-924d-cf749e0aab42%40googlegroups.com.

Reply via email to