>
> db.define_table('contract',
> Field('num', unique=True, notnull=True'),
> ...
>
> db.define_table('student',
> Field('contract', db.contract, unique=True, notnull=True,
> label='Договор'),
>
> But unique and notnull options doesnt reflects in database.
>
> In generally, how I can make one to one relation? I've tried the following
> approach:
>
> db.student.contract.requires = IS_NOT_IN_DB(db, 'student.contract')
> db.student.contract.requires = IS_IN_DB(db, db.contract.id, '%(num)s')
>
> but the first requirements (IS_NOT_IN_DB) doesn't work.
>
Above, first you set the requires attribute to the IS_NOT_IN_DB validator,
but then you change the attribute and instead set it to the IS_IN_DB
validator. It's not that IS_NOT_IN_DB isn't working -- the problem is that
it is no longer one of the field's validators. If you want multiple
validators, put them in a list (see
http://web2py.com/books/default/chapter/29/07#Validators).
Also, if there is only one student per contract and one contract per
student, why not just put everything in one table?
Anthony
--