You can but you would lose refence integrity: 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', 'integer'), db.Field('task', 'string')) db.student.student_id.requires=IS_NOT_IN_DB(db,'student.student_id') db.tasks.student_id.requires=IS_IN_DB(db,'student.student_id') I suggest instead: db.definetable('student', db.Field('student_id', 'integer'), db.Field('first_name', 'string'), db.Field('last_name', 'string)) db.definetable('tasks', db.Field('student', db.student), db.Field('task', 'string')) db.student.student_id.requires=IS_NOT_IN_DB(db,'student.student_id') db.tasks.student.requires=IS_IN_DB(db,'student.id','%(student_id)s') db.tasks.student.represent=lambda id: db.student[id].student_id Massimo On Jul 27, 10: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 -~----------~----~----~----~------~----~------~--~---