activerecord - Changing enum value in Rails without saving model -
how change enum value without saving model database yet?
the documentation activerecord::enum indicates methods conversation.active!
, conversation.status = "archived"
equivalent doing conversation.update! status: 1
, whereas i'm getting attributes simple_form form, , don't want save model until of attributes have been set, otherwise model won't valid.
the bang version of method - conversation.active!
save database immediately.
the other way - conversation.status = "archived"
not, , require explicit conversation.save!
afterwards. so, that's method you're after.
(btw, rails console handy testing stuff this, , show exact sql gets executed bang version of method, execute it)
Comments
Post a Comment