I made a simple patch that lets this work and is seemingly backwards
compatible (didn't break my apps anyway).  It basically automatically
does a select for any reference fields so you can do this (db.things
has a reference field 'author' to auth_user in this example):

record = db(db.things.id==1).select()[0]
print record.author.email

What do you think?

### Eclipse Workspace Patch 1.0
#P web2py
Index: gluon/sql.py
===================================================================
--- gluon/sql.py        (revision 1310)
+++ gluon/sql.py        (working copy)
@@ -451,6 +451,8 @@
             else:
                 return "'F'"
     if fieldtype[0] == 'i':
+        if isinstance(obj,DALStorage):
+            return str(int(obj.id))
         return str(int(obj))
     elif fieldtype[0] == 'r':
         if fieldtype.find('.')>0:
@@ -2926,7 +2928,7 @@
             if field.type[:10] == 'reference ':
                 referee = field.type[10:].strip()
                 rid = value
-                row[tablename][fieldname] = rid
+                row[tablename][fieldname] = self._db(self._db[referee]
['id']==rid).select()[0]
             elif field.type == 'blob' and value != None:
                 row[tablename][fieldname] = base64.b64decode(str
(value))
             elif field.type == 'boolean' and value != None:



On Oct 26, 11:47 pm, "mr.freeze" <[email protected]> wrote:
> Also, why doesn't this work?:
>
> record = db(db.tablename.id==1).select()[0]
> print record.author.email
>
> It seems like it should work since author is a reference to auth_user
> and it's referencing a distinct record.
>
> On Oct 26, 11:25 pm, mdipierro <[email protected]> wrote:
>
> > Given:
>
> > ... Field("author", db.auth_user, default=auth.user.if if auth.user
> > else 0) ...
>
> > db.tablename.author.requires=IS_IN_DB(db,'auth_user.id','%(first_name)
> > s %(last_name)s')
>
> > You can do
>
> > record = db(db.tablename.id>0).select().first()
> > print db.auth_user[record.author].first_name
>
> > and/or
>
> > row= db(db.tablename.author==db.auth_user.id).select.first()
> > print row.tablename, row.auth_user.first_name
>
> > On Oct 26, 10:58 pm, Wiiboy <[email protected]> wrote:
>
> > > And then how would I get the user's info?
>
> > > db(db.auth_user.id == db.tablename.author)
>
> > > ?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to