Hi all,

So I always knew there was *this *shorthand for getting the field 
attributes of a 'reference' type field:
row.competition_entry.entrant.name

What I did not discover until recently is that ALL references can be 
followed as far as they have been defined. For example:

row.competition_entry.entrant.registered_by.name

Works even if the query is just:

db(db.competition_entry).select()

I was jumping through hoops because before even attempting the above, I was 
doing:

db(db.competition_entry.registered_by == db.registrant.id).select()

Which is not needed if registered_by is a reference to registrant. I had 
assumed that you needed the joins to have second and third degree 
information. In fact, for a complex data structure, this works just fine 
with that simple single-table select:

row.competition_entry.competition_section.category.sponsor.name

That is, we a sponsor for each whole competition category (containing 
multiple sections), into which competitors place their entries. 

Getting the name of the sponsor really does work like that, even if the 
query was just db(db.competition_entry).select() -- You would 
probably appreciate how complex my queries had been to get the sponsor 
name, just by misunderstanding the DAL!

I really hope this helps someone -- now I am going off to remove a LOT of 
table joins in my queries!

As an aside, does this mean my Web2Py sessions will be reasonably large, 
because competition entry rows on their own have a lot of baggage about 
competition-section-category-sponsors and registered_by info?, ...or is 
Web2Py smart enough to only call in that extra information if required? (I 
find it hard to believe it is on-demand, since Web2Py would surely need to 
launch another query just for these references, yes?)

Thanks,
Duncan.

-- 
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/groups/opt_out.

Reply via email to