From 7e5c5e4d8c6c9346b8669db9faa4c3dced374646 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Oct 2013 14:10:57 -0700 Subject: don't access the reflections hash The reflections hash is supposed to be private, so let's use the API. --- activerecord/lib/active_record/associations/join_dependency.rb | 8 ++++++-- .../lib/active_record/associations/join_dependency/join_part.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index c9c50da36e..80cf933555 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -144,11 +144,15 @@ module ActiveRecord ref[association.reflection.name] ||= {} end + def find_reflection(klass, name) + klass.reflect_on_association(name.intern) or + raise ConfigurationError, "Association named '#{ name }' was not found on #{ klass.name }; perhaps you misspelled it?" + end + def build(associations, parent, join_type) case associations when Symbol, String - reflection = parent.reflections[associations.intern] or - raise ConfigurationError, "Association named '#{ associations }' was not found on #{ parent.base_klass.name }; perhaps you misspelled it?" + reflection = find_reflection parent.base_klass, associations unless join_association = find_join_association(reflection, parent) @reflections << reflection join_association = build_join_association(reflection, parent, join_type) diff --git a/activerecord/lib/active_record/associations/join_dependency/join_part.rb b/activerecord/lib/active_record/associations/join_dependency/join_part.rb index 8024105472..2b6034ca9d 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb @@ -13,7 +13,7 @@ module ActiveRecord # association. attr_reader :base_klass - delegate :table_name, :column_names, :primary_key, :reflections, :arel_engine, :to => :base_klass + delegate :table_name, :column_names, :primary_key, :arel_engine, :to => :base_klass def initialize(base_klass) @base_klass = base_klass -- cgit v1.2.3