granite icon indicating copy to clipboard operation
granite copied to clipboard

Expand unique validations with scoped and case-insensitive

Open caspiano opened this issue 5 years ago • 1 comments

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

caspiano avatar Dec 31 '20 02:12 caspiano

Related https://github.com/amberframework/granite/issues/358.

Blacksmoke16 avatar Jan 01 '21 00:01 Blacksmoke16

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.

crimson-knight avatar Apr 25 '23 12:04 crimson-knight