Be careful, as using recursive selects (as these are called) is not very efficient (a separate query for each attribute retrieved in each record). Should be fine if you only need to do a few per request, but more efficient to do a join if dealing with many records at a time (particularly if you need to sort a large number of records). Each individual select should be relatively quick, as it is simply pulling from a single table via primary key, but still, they can add up. You can check the "db timings" tab in response.toolbar() to get an idea how long all the queries are taking in a given request.
In the future, it could be interesting to do something like SQLAlchemy and have the recursive attributes filled in all at once by doing a join or subquery behind the scenes. At the very least, once a given recursive select is performed, perhaps we could store the record so it doesn't need to be retrieved again on subsequent accesses. Anthony On Saturday, February 15, 2014 7:02:04 AM UTC-5, duncan macneil wrote: > > > Hi again, > > Sorry to keep posting here, but I really think this information must be > useful as it is to me. > > Now, you can't just use deep references in the format attribute for a > table, so you use a lamda. Something like: > > format=lambda r: r.schedule.company.name + ': ' + r.schedule.name + ': ' > + r.descrip + ' - ' + r.done_by.name > > Also, when it comes to sorting, you can't just say: > > select(sortby=db.mytopic.schedule.company.name) > > > nor can you use: > > select(sortby=db.company.name) > > > (It works, but you get a loose join and too many rows returned. Probably > distinct would fix, but, meh.) > > So instead you can wait until the results are returned as use: > > rows.sort(lamba row: row.schedule.company.name) > > > and to sort multiple columns: > > rows.sort(lambda row: row.schedule.company.name + row.schedule.name) > > Again, hope this helps. It is speeding up my designs very much. > > Finally, don't use this pattern if you allow nulls in the table, such as > having a topic which is not forced to be assigned to schedule/company to > begin with, for instance. Or if you do, make sure you check for None type > objects in these deep references. > > Regs. > > -- 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]. For more options, visit https://groups.google.com/groups/opt_out.

