On Fri, Oct 2, 2009 at 9:39 PM, BioNip <bionic.nip...@gmail.com> wrote:
> > Consider this code: > > > db.define_table('position', > > Field('name'), > > Field('sort_order', 'integer'), > > ) > > > > db.define_table('person', > > Field('name'), > > Field('position', db.position), > if you named this field this way, it would be clearer to you (perhaps - I'm assuming you're a programmer): Field('position_id', 'reference position') > ) > > > > #This sorts by the position.id > > db(db.person.name=='Bob').select(orderby=db.person.position) > Since a foreign key _is_ a reference, and in this case specifically, a reference to the other table's id - you are sorting this field by "it's value" - once you see that, you should not be surprised - position_id is, specifically, an integer which contains the id (key) of another table; you are sorting integers, so that is what you get. > > > > #This fails. > > db(db.person.name=='Bob').select(orderby=db.person.position.sort_order) > Since there is no such thing or structure as db.person.position_id.sort_order (you see - position_id is an integer, NOT a structure - it is merely a reference by id!), and you are suggesting an inner join > > I want a list of people, ordered by their position.sort_order, not > position.id . Does anyone know how this can be accomplished? > I'll let you try to work this out - hint: you want to sort the field IN THE position table (not the person table), and you are suggesting something that should be reminiscent of an inner join ('inner' being intersection rather than union, as an outer join would be) of tables - there are examples showing almost what you want in the manual (instead of the groupby, use oderby). Try to figure it out; let us know if you get stuck. Regards, - Yarko > Thanks. > > > -nip > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---