>
> db.combinada.primero.requires = 
> [IS_NOT_IN_DB(db(db.combinada.combinado==str(request.vars.primero) 
> +str(request.vars.segundo)), "combinada.combinado"), IS_NOT_EMPTY()] 
>

The value of request.vars.primero will be passed to the above IS_NOT_IN_DB 
validator, but it is then comparing that value against values in the 
"combinado" field -- so even when the "combinado" value is duplicated, it 
won't return an error because the value of "primero" won't match the 
duplicated value of "combinado". Instead, you should compare the value of 
request.vars.primero to values in the "primero" field, but only among the 
set of records that match the current value of request.vars.segundo -- 
that's what the example on Stack Overflow is doing. The idea is that you're 
looking for a set of records where "primero" is duplicated among a set of 
records where "segundo" is also duplicated, which implies that the 
combination of "primero" and "segundo" is duplicated.

db.combinada.primero.requires = 
[IS_NOT_IN_DB(db(db.combinada.segundo==request.vars.segundo),
    "combinada.primero", error_message='The combination of primero and 
segundo must be unique'),
     IS_NOT_EMPTY()] 

Anthony

Reply via email to