-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Make reflection and aggregate_reflection caches work with string keys. #14675
Make reflection and aggregate_reflection caches work with string keys. #14675
Conversation
with strings with string keys. Related #14668.
It definitely shouldn't be touching the has directly like that. Do we have accessor functions for the hash? Aaron Patterson
|
…rks_with_string_keys Make reflection and aggregate_reflection caches work with string keys.
Yes, they are using the |
end | ||
|
||
def source_reflection_name # :nodoc: | ||
return @source_reflection_name.to_sym if @source_reflection_name | ||
return @source_reflection_name if @source_reflection_name | ||
|
||
names = [name.to_s.singularize, name].collect { |n| n.to_sym }.uniq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing that doesn't actually affect this piece where it looks for the real name, right? The "names" method is only used in an exception as far as I could see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carlosantoniodasilva yes, you are right. Thanks bro!
In PR rails#14675 reflection cache / associations were changed to accept string as keys. The problem is this messed up the ability to accepts symbols as keys. There were no tests to make sure both strings and symbols could be accepts. This was brought to light when I attempted to fix rails#15671.
Update the code that uses the internal rails api to be compatible with rails 4.2. > ActiveRecord::Base#reflections now returns a hash with string keys instead of symbol keys. [PR] rails/rails#14675
Following @tenderlove's suggestion on #14668 (comment), now the
reflection
and theaggregate_reflection
caches use String as keys. This is needed to avoidto_sym
in some cases, such as did in #14668.I think we won't have problems changing these caches, since they are only used in
reflection.rb
file.Another point is the test. I think it is wrong, it should not use the
reflection
Hash, right?cc/ @tenderlove