Validation
Validation
Can I validate that a field is unique in relation to other fields?
I will try and explain:
Table looks like this:
| process_type_id | stream_id | fault_id | rank |
|-----------------|-----------|----------|----------------|
| 1 | 1 | 22 | 1 |
| 1 | 1 | 45 | 2 |
| 1 | 1 | 5 | 3 |
| 1 | 1 | 1 | 4 |
| 1 | 1 | 9 | 4 (not valid) |
process_type_id and stream_id are foreign keys and rank is an integer 1-9 which needs to be unique to for a process and stream.
Cheers,
Mick
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Mick,
The built in
dbUnique
validator doesn't have an option to specify awhere
clause (although I can see how that would be useful and will look into that option for the future). Instead, you would need to use a custom validator that would query the database to ensure that the value is unique across the two data points. You could also apply a unique constraint on the database table itself to make sure that it doesn't get incorrect data into the table, ever.Regards,
Allan