railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.9k stars 2.26k forks source link

Enums being automatically set after update #2993

Open vitormd opened 6 years ago

vitormd commented 6 years ago

Problem:

Describe: Updating entities through rails_admin

Contexts:

It is wrongly updating the enum to the first possible value instead of letting it stay empty/null

There where some improvements on the way rails_admin deals with enum recently, and all seen good, but they generated this bug where it is updating enum values when is not wanted.

Rails version: 5.0.6

Ruby version 2.5.0

chiperific commented 5 years ago

Same here.

chiperific commented 5 years ago

Looking for work-arounds: https://stackoverflow.com/questions/58100255/rails-admin-wont-let-me-keep-my-enum-field-as-nil

chiperific commented 5 years ago

This problem is present when the database column is an integer. It might not be present if using Postgres ENUM field type.

chiperific commented 5 years ago

If you declare your enum as a hash (not an array), and don't assign anything to 0, it works.

In my case enum recurrence: { daily: 0, weekly: 1, monthly: 2, annually: 3 } becomes enum recurrence: { daily: 1, weekly: 2, monthly: 3, annually: 4 }