Validation on multiple column not associated with a specific column

28 Views Asked by At

I'm writing an ActiveRecord model and I want to validated the uniqueness of a row based on values in multiple columns. It should look like this:

    validates :column_a, {
      uniqueness: {
        scope: [:column_b, :column_c],
      }
    }

Here's the thing. It feels awkward. If the validation fails, The ActiveModel attribute will have the column_a value and the default rails behaviour would be to start the error message with column a. So I guess I it's easy to create a workaround by overriding the default error message but is there a more idiomatic way to approach this?

0

There are 0 best solutions below