I'm an idiot. I actually hadn't tried the transaction.product.name syntax, and lo-and-behold, it works.
web2py is awesome. On Jul 22, 8:31 pm, scausten <[email protected]> wrote: > There's a really cool feature in the CakePHP web framework whereby you > can query a database recursively and have a query return not only the > records of a given query, but also any other records they refer to, > and I was wondering if there's anything similar in web2py. (There is a > 'recursive' flag in the CakePHP 'find' function 0=don't return > referenced records, 1=return referenced records, 2=return referenced > records AND the the records they reference, etc.!) > > For example, say you have two tables, products and transactions: > > db.define_table('products', Field('name'), Field('Description'))) > db.define_table('transactions', Field('product', db.products)) > > So, a query on 'transactions' returns something like: > > transaction: id: 1 > product: 12 > > then to get the data for product.id==12, you have to do > db.products[transaction.product] or similar to get the product data. > > However, is it possible to make the query return, not the id of the > referenced record, but the actual DALStorage object representing the > object itself?: > > transaction: id: 1 > product: name: "Product 1" > description: "This is a test > product" > > Then I envisage being able to directly reference, for example, > transaction.product.name > > In practise, I want to display to product name for a given transaction > in multiple places in a page, and the only options I can see are > separately storing the product data, or calling > db.products[transaction.product] wherever I need it: the first seems a > bit clunky and the second requires a separate call to the db every > time. I could select the product data and cache it, I'd prefer not to. > > I would love to know if what I've described, above, is possible. > > Any ideas? > > Si

