vprokopchuk256 / mv-postgresql

Postgresql constraints in migrations similiar to ActiveRecord validations
MIT License
20 stars 2 forks source link

Allow `nil` for inclusion validation #5

Closed greyblake closed 8 years ago

greyblake commented 8 years ago

Hi, thanks for the nice gem!

I wonder, is it possible to instrcut inclusion validator to allow NULL for nullable columns? E.g. like this:

validates :table_name, :column_name, inclusion: { in: [nil, 1, 2, 3] }

Спасибо)

greyblake commented 8 years ago

Figured it out. I had to use allow_nil option:

validates :table_name, :column_name, inclusion: { in: [1, 2, 3], allow_nil: true }