On Sat, Oct 3, 2009 at 9:42 AM, mdipierro <[email protected]> wrote:
> > db(db.person.name=='Bob')(db.person.position==db.position.id).select > (orderby=db.position.sort_order) > To annotate this a little more - Checking P. 16 of the manual (*Inner Joins*) you'll see that web2py DAL performs these transparently wherever the query references two or more tables - so that the way you think of it should be natural. In this case, you want to join the Person's position with the Position's sort order - and here it is: db( WHERE clause ) . select ( SELECT clause ) --- the sql "from" is what is implicit, and transparent, in this case a join of db.person and db.position, as implied by the WHERE clause. Look at it this way: db( where *person.name *is 'Bob', and *person.position_id *is described by * position.id *).... that last piece translates cleanly, naturally into SQL that would look like: FROM person INNER JOIN position ON person.position_id == position.id (much nicer, the way you naturally express this in DAL!) Now, with a join in DAL, the result is returned by [tablename].[column_name] - that's all you need to remember to process the results in your code. Since you have anything from either table at your disposal, the sort you want is (properly - once you understand what the nature of person.position_id - which, remember, I insisted you rename so you wouldn't forget what this is!) no more complicated than what you want: .... .select( orderby=db.position.sort_order) This is a lot of explanation, but hopefully you will now more easily be able to remember what the fields are that you are working with, what you want to tell web2py to do (how to translate your sentence), and how that is (simply) expressed for the DAL. Regards, - Yarko --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

