I have a model with field a, b. I want to make sure that the combination of a and b is unique in the table, so a=1, b=2 and a=2, b=1 would raise a conflict.
I have try validates_uniqueness_of :a, :scope => :b, but it only make sure that no two
a=1, b=2 row can exist, I also want to filter out the a=2, b=1. Thanks
The built-in uniqueness validator does not support that, as far as I know. You would have to write a custom validation for that, e.g.:
This will add a validation error to attribute
aif there is any record having (a = 1 AND b = 2) OR (a = 2 AND b = 1).