Skip to content

Commit

Permalink
Merge pull request #14675 from laurocaetano/make_reflection_caches_wo…
Browse files Browse the repository at this point in the history
…rks_with_string_keys

Make reflection and aggregate_reflection caches work with string keys.
  • Loading branch information
tenderlove committed Apr 10, 2014
2 parents c7d009b + 213ef56 commit 82cb477
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions activerecord/lib/active_record/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/reflection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82cb477

Please sign in to comment.