Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 7.1+ Enum Validation #205

Open
egreer opened this issue Jan 3, 2025 · 0 comments
Open

Rails 7.1+ Enum Validation #205

egreer opened this issue Jan 3, 2025 · 0 comments

Comments

@egreer
Copy link

egreer commented Jan 3, 2025

Rails 7.1+ introduced validation on enums in rails/rails#49100.

class Attachment < ApplicationRecord
  enum :attachment_type,
       { report: 'report', note: 'letter' },
       default: 'report',
       validate: true
       ...

When backed by a string the incorrect_length_validation raises:

the schema limits attachments.attachment_type to 255 characters but there's no length validator on Attachment.attachment_type - remove the database limit or add the validator

The validates_inclusion_of used under the hood by enum validation only accepts the options for :allow_nil, :allow_blank` and doesn't allow passing additional length validations.

I'd like a way to silence this without having to configure an ignore for each one. Or if possible check the enum options to ensure none of them have a length greater then the database col max when validate: true or validate: { allow_nil: true }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant