Something strange in my query

40 views
Skip to first unread message

Константин Комков

unread,
Dec 9, 2019, 5:30:00 AM12/9/19
to web...@googlegroups.com
My query return attribute 'a_students' for row, but in select I wrote 'db.a_groups.NAME'. Why?
Web2py 2.18.5-stable+timestamp.2019.04.08.04.22.03
(Running on Rocket 1.2.6, Python 3.7.3)

tables.py
db.define_table(
 
'a_groups',
 
Field('ACADEMIC_YEAR', 'integer'),
 
Field('NAME', length=25),
 
Field('STATUS', 'integer'),
 
Field('INACTIVE', 'integer', rname='"INACTIVE"'),
 
Field('FO', 'integer'),
 
Field('WLP', 'integer'),
 
Field('FAC', 'reference t_fac'),
 migrate
=False
)

db
.define_table(
 
'a_students',
 
Field('GROUP_ID', 'reference a_groups'),
 migrate
=False
)

db
.define_table(
 
'tt_main',
 
Field('GROUP_ID', 'reference a_groups'),
 
Field('MODULE', 'integer'),
 migrate
=False
)

default.py
groups = db((db.a_groups.FO == 1) & (db.a_groups.FAC == faculty) & (db.a_groups.STATUS == 2) &
 
(db.a_groups.INACTIVE == 0)).select(db.a_groups.id, db.a_groups.NAME)
for row in groups:
 
...
then I have error becouse row don't have 'a_groups'. Why I have 'a_students' attribute?
<Row {'id': 1754, 'a_students': <Set (a_students...et (tt_main.GROUP_ID = 1754)>, 'NAME': 'Д-А401'}>

Константин Комков

unread,
Dec 9, 2019, 6:18:22 AM12/9/19
to web...@googlegroups.com
I understood, that I select only one table and need take row.NAME without tablename. But it's interesting what is a_students attribute?

Val K

unread,
Dec 9, 2019, 11:14:43 AM12/9/19
to web2py-users
As you can see, this is a Set, not just an attribute. When you select from a table that has FK, Pydal forms Sets for related tables, Set is the type that db (...) returns
Reply all
Reply to author
Forward
0 new messages