DAL: How to define compound keys.

27 views
Skip to first unread message

tiago almeida

unread,
Jan 18, 2010, 9:17:10 AM1/18/10
to web...@googlegroups.com
Hello all,

What should one do to force a specific pair of columns to be unique?

Lets say I have a table where 2 of the columns are "user" and "bookmark" and I want the database to force the pair (user,bookmark) to be unique so that a specific user doesn't insert the same bookmark twice or more. Is it possible to do this with DAL? The only solution I see is to explicitly check for the existence of that pair with a select..

Thanks a lot in advance,

Tiago Almeida

mdipierro

unread,
Jan 18, 2010, 10:27:56 AM1/18/10
to web2py-users
This comes up often. You have to enforce at the validators level.

db.define_table('t',Field('a'),Field('b'))

db.t.b.requires=IS_NOT_IN_DB(db(db.t.a==request.vars.a),db.t.b)

tiago almeida

unread,
Jan 18, 2010, 10:31:52 AM1/18/10
to web...@googlegroups.com
I see. Thank you for your prompt answer :)

Tiago Almeida
----------

--
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.




Reply all
Reply to author
Forward
0 new messages