-
Notifications
You must be signed in to change notification settings - Fork 47
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
each_instance doesn't handle enum attributes? #40
Comments
Thanks, @chickenburgers (what a cool name!) I looked on this again today. As far as I can tell, I'm doing the correct thing in instantiating the record. The enum's act as if they aren't defined. Could be an activerecord issue? Or there is a newer way to to it? Frustrating. 😢 |
@afair I'm wondering why |
FIX #40: Handle enum attributes while instantiating rows
Revert "FIX #40: Handle enum attributes while instantiating rows"
First of all, great gem, love it 👍
I've only run into a problem with enum attributes in ActiveRecord. If I define a model with an enum attribute, .each() outputs the symbolic enum value, but .each_instance() outputs the underlying numeric value. e.g.
class User < ApplicationRecord
enum gender: [:male, :female]
end
User.all.each {|u| puts u.gender} # Outputs "male", "male", "female"
User.all.each_instance {|u| puts u.gender} # Outputs 0, 0, 1
The text was updated successfully, but these errors were encountered: