On Fri, Mar 20, 2009 at 9:41 AM, Speedbird <[email protected]> wrote:

>
> In this particular line (I just assigned it to a variable for
> exmpanation purposes)::
>
> recs = db().select(db.jobs.description,u1.name,u2.name, left=(u1.on
> (db.jobs.user1==u1.id),u2.on(db.jobs.user2==u2.id)))
>
> How do you reference "u1.name" or "u2.name"? - Consider the following:
>
> row1_desc = recs[0].description
> row1_name = recs[0].name # <--- What Name????


in both inner and out joins, select returns unambiguous elements, e.g.:

    for row in recs:
         print row.u1.name, row.u2.name, row.jobs.description

- Yarko

>
>
> Or am I way off base here?
>
> Thanks in advance for any help!
>
> jf/sb
>
>
> On Mar 17, 8:15 am, ls1 <[email protected]> wrote:
> > Thanks a lot. Works great!
> >
> > Small correction, aliases should be with 'db.' prefix:
> >
> > u1=db.users.with_alias('u1')
> > u2=db.users.with_alias('u2')
> > db().select(db.jobs.description,u1.name,u2.name,
> left=(u1.on(db.jobs.user1==u1.id),u2.on(db.jobs.user2==u2.id)))
> >
> > On 17 Mar, 16:05, mdipierro <[email protected]> wrote:
> >
> >
> >
> > > This should do it:
> >
> > > u1=users.with_alias('u1')
> > > u2=users.with_alias('u2')
> > > db().select(db.jobs.description,u1.name,u2.name,
> > >   left=(u1.on(db.jobs.user1==u1.id),u2.on(db.jobs.user2==u2.id)))
> >
> > > On Mar 17, 9:48 am, ls1 <[email protected]> wrote:
> >
> > > > Let's consider following tables:
> >
> > > > db.define_table('users', SQLField('name'))
> > > > id1=db.users.insert(name='user A')
> > > > id2=db.users.insert(name='user B')
> >
> > > > db.define_table('jobs',
> > > >                        SQLField('description'),
> > > >                        SQLField('user1',db.users),
> > > >                        SQLField('user2',db.users))
> > > > db.jobs.user1.requires=IS_IN_DB(db,'users.id','%(name)s')
> > > > db.jobs.user2.requires=IS_IN_DB(db,'users.id','%(name)s')
> >
> > > > db.jobs.insert(description='some job to do', user1=id1, user2=id2)
> >
> > > > Simple query like this will give me name of user1:
> > > > db(db.jobs.user1==db.users.id).select(db.jobs.description,
> > > > db.users.name)
> >
> > > > Question: how to make query to show 'description' from table 'jobs'
> > > > together with names of the 2 users taken from table users?
> > > > something like:  jobs.description   user1.name    user2.name- Hide
> quoted text -
> >
> > - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to