thetron / mongoid-enum

Sweet enum sugar for your Mongoid documents
MIT License
117 stars 167 forks source link

Underscore in field name #12

Closed d4rk5eed closed 9 years ago

d4rk5eed commented 9 years ago

What is the reason for using underscore in fieldname?

> Meeting.new.attributes
=> {"_id"=>BSON::ObjectId('549d746563616c2168060000'), "_meeting_quality"=>:hd, "_status"=>:inactive}

Actually we get another attribute that differ one we created

xpepermint commented 9 years ago

Asking the same question! Btw... I think that enum options should be strings (e.g. enum status: ["pending", "ready"] ). +1

alexanderk23 commented 9 years ago

+1

bhirsch42 commented 9 years ago

+1

thetron commented 9 years ago

To be honest - I can't 100% remember my motivations for doing this. If I had to guess - it was probably to indicate that the field shouldn't be directly access, except through the getters and setters - following on from a few other (similar) gems that do similar things.

@xpepermint What are your thoughts on strings vs. symbols? I felt like symbols would be a better choice here, given that the values are immutable, but curious to hear why you feel these should be strings.

xpepermint commented 9 years ago

@thetron Huh, I don't remember exactly why but I think I was looking at rails enum function which works on strings.

nofxx commented 9 years ago

There's 5+ forks only to remove the underscore. +1 for me hehe.

thetron commented 9 years ago

Thanks everyone again for your feedback here. I've merged in #12, which added a configuration option to customise the prefix. At some point in the future we might switch the default to be an empty string, but I wanted to make it easy for existing and future users to continue using the gem on the path to v1.0.0, and support for mongoid 5.

:cake: