I believe that if you want to use the DAL's reference then you must reference the foreign table's row via its id field (this hidden field). If you want use a different field then you must construct a join. Something like:
q = db(db.tasks.student_id==db.student.student_id) #this 'row selection' creates a SQLquery object. rows = q.select(db.tasks.ALL, db.student.first_name) # this column selection performs the actual db collection/creation of the resultset for row in rows: print row.tasks.student_id, row.tasks.task, row.student.first_name Note above that the first two lines are often combined into: rows = db(db.tasks.student_id==db.student.student_id).select (db.tasks.ALL, db.student.first_name) --- Rb PS. it's all in the Programmer's Guide pdf. (There's a new version coming out shortly). On Jul 27, 8:12 pm, Alastair Medford <alastairmedf...@gmail.com> wrote: > I've been looking into creating a table reference (or foreign key) in > web2py and have only found db.Field('name', db.otherTable). Now as I > understand it, this creates an integer field in the table that > contains the "hidden" web2py integer id of the entry in the other > table. Is this the case? > > If so, is there any way to reference on a different unique field? For > the sake of example, consider this table definition: > > db.definetable('student', > db.Field('student_id', 'integer'), > db.Field('first_name', 'string'), > db.Field('last_name', 'string)) > > db.definetable('tasks', > db.Field('student_id', db.student), > db.Field('task', 'string')) > > Is there any way for student_id in the tasks table to contain the > actual student_id, and not the web2py id? I haven't been able to find > many details on the subject. > > Also sorry if I do not respond quickly, I'm traveling currently and > never really know when I'll have wifi again. Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---