Hello,
I just found a way to avoid _before_insert and _before_update callbacks and
implement at the form level the unique constraint apply at backend level
over 2 fields like so :
ALTER TABLE table_name
ADD CONSTRAINT unique_f1_and_f2
UNIQUE (f1, f2);
What works for me in my picilar use case is to use IS_NOT_IN_DB() with set
like this :
fields_combination_set = db(db.table_name.f2 == request.vars.fk_id)
db.table_name.f1.requires = IS_NOT_IN_DB(fields_combination_set,
'table_name.f1')
My f2 field is a foreign key and I get the value from another form that
redirect on the form where the IS_NOT_IN_DB() validators will be used...
What I want to acheive is avoid combination of multiples revision number
for a given parent record... So my f1 field is a revision number and my f2
is the parent record id for which the revision number applies.
Hope it could help some and if I need that again in the future I may found
this email quickly...
:)
Richard
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.