Permalink
Browse files

Merge pull request #14675 from laurocaetano/make_reflection_caches_wo…

…rks_with_string_keys

Make reflection and aggregate_reflection caches work with string keys.
  • Loading branch information...
2 parents c7d009b + 213ef56 commit 82cb4777c148962467b04ee29fb49063462c56d8 @tenderlove tenderlove committed Apr 10, 2014
Showing with 7 additions and 7 deletions.
  1. +6 −6 activerecord/lib/active_record/reflection.rb
  2. +1 −1 activerecord/test/cases/reflection_test.rb
@@ -22,11 +22,11 @@ def self.create(macro, name, scope, options, ar)
end
def self.add_reflection(ar, name, reflection)
- ar.reflections = ar.reflections.merge(name => reflection)
+ ar.reflections = ar.reflections.merge(name.to_s => reflection)
end
def self.add_aggregate_reflection(ar, name, reflection)
- ar.aggregate_reflections = ar.aggregate_reflections.merge(name => reflection)
+ ar.aggregate_reflections = ar.aggregate_reflections.merge(name.to_s => reflection)
end
# \Reflection enables to interrogate Active Record classes and objects
@@ -48,7 +48,7 @@ def reflect_on_all_aggregations
# Account.reflect_on_aggregation(:balance) # => the balance AggregateReflection
#
def reflect_on_aggregation(aggregation)
- aggregate_reflections[aggregation]
+ aggregate_reflections[aggregation.to_s]
end
# Returns an array of AssociationReflection objects for all the
@@ -72,7 +72,7 @@ def reflect_on_all_associations(macro = nil)
# Invoice.reflect_on_association(:line_items).macro # returns :has_many
#
def reflect_on_association(association)
- reflections[association]
+ reflections[association.to_s]
end
# Returns an array of AssociationReflection objects for all associations which have <tt>:autosave</tt> enabled.
@@ -617,11 +617,11 @@ def association_primary_key(klass = nil)
# # => [:tag, :tags]
#
def source_reflection_names
- (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).collect { |n| n.to_sym }.uniq
+ (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).collect { |n| n }.uniq
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
names = names.find_all { |n|
@@ -192,7 +192,7 @@ def test_association_reflection_in_modules
end
def test_reflection_should_not_raise_error_when_compared_to_other_object
- assert_nothing_raised { Firm.reflections[:clients] == Object.new }
+ assert_nothing_raised { Firm.reflections['clients'] == Object.new }
end
def test_has_many_through_reflection

0 comments on commit 82cb477

Please sign in to comment.