-
Notifications
You must be signed in to change notification settings - Fork 33
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
ID as symbols. #28
base: master
Are you sure you want to change the base?
ID as symbols. #28
Conversation
Thanks very much! See #20 - it was my dream... And what about |
The reason this PR came about was because we were initially using strings as IDs and it was causing all sorts of issues. While I think that it can be done, after some discussion, we decided that it was best not to implement as it, quickly becomes confusing as to what is what, and the get and meta functions would need more of a rework. Using IDs as symbols and names as strings, it's far easier to differentiate between the two. |
Thanks very much for deep explanation! |
I think that attribute setter is not working as expected. This code from extensions.rb def define_active_enum_write_method(attribute)
class_eval <<-DEF
def #{attribute}=(arg)
if arg.is_a?(Symbol)
super self.class.active_enum_for(:#{attribute})[arg]
else
super arg
end
end
DEF
end causes saving name value to database, not id. |
And same for getter: string loaded from database, so it doesn't find value in storage. |
Just got back from a month holiday. Will have a look at this once I've been back behind the keyboard for a while and in a proper frame of mind. No doubt the test coverage will need to be expanded to cover this. |
I'm sorry, but have you looked at this? Is it hard to correct? |
I haven't had a chance yet. Had a few major deadlines lately, however this is on the list of things to fix and review as it's come up in development of one of our apps. |
I also have the need for string ids. For now I solved it by forking active_enum and replacing all the checks for I'm not yet sure as to what's better: Enforcing symbols or strings for IDs. In any case it breaks some behaviour of the bracket/get accessor. |
Finally, I corrected some problems and added tests in my PR: #38 |
Add functionality to active_enum to be able to use symbols as IDs.
Example usage