granite
granite copied to clipboard
Expand unique validations with scoped and case-insensitive
Allow uniqueness validations scoped by other fields on the model. Additionally, allow case-insensitive uniqueness validations.
Usage:
class Post < Granite::Base
connection mysql
column id : Int64, primary: true
column title : String
column year : Int32
validate_uniqueness(
:title,
scope: :year, # Scope can also accept an array of fields
case_insensitive: false # Default to strict case sensitivity
)
end
Related https://github.com/amberframework/granite/issues/358.
I'm going to close this since it's tightly related to the RFC issue already cited. I think the recommendation makes sense and will naturally come about during the validation improvement process.