From 8e1b363167c22adcf75e3454dc8bfd34b5801d79 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 3 Oct 2013 15:13:55 -0700 Subject: Set the join type on construction We always set the join type immediately after construction, just make it part of the constructor and we can skip that step --- activerecord/lib/active_record/associations/join_dependency.rb | 7 +++---- .../active_record/associations/join_dependency/join_association.rb | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 00fe249837..b6bd37d3cb 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -137,8 +137,7 @@ module ActiveRecord raise ConfigurationError, "Association named '#{ associations }' was not found on #{ parent.base_klass.name }; perhaps you misspelled it?" unless join_association = find_join_association(reflection, parent) @reflections << reflection - join_association = build_join_association(reflection, parent) - join_association.join_type = join_type + join_association = build_join_association(reflection, parent, join_type) @join_parts << join_association cache_joined_association(join_association) end @@ -173,14 +172,14 @@ module ActiveRecord end end - def build_join_association(reflection, parent) + def build_join_association(reflection, parent, join_type) reflection.check_validity! if reflection.options[:polymorphic] raise EagerLoadPolymorphicError.new(reflection) end - JoinAssociation.new(reflection, self, parent) + JoinAssociation.new(reflection, self, parent, join_type) end def construct(parent, associations, join_parts, row) diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index 3bc7f7ad50..2307564ce7 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -29,13 +29,13 @@ module ActiveRecord delegate :options, :through_reflection, :source_reflection, :chain, :to => :reflection delegate :alias_tracker, :to => :join_dependency - def initialize(reflection, join_dependency, parent) + def initialize(reflection, join_dependency, parent, join_type) super(reflection.klass) @reflection = reflection @join_dependency = join_dependency @parent = parent - @join_type = Arel::InnerJoin + @join_type = join_type @aliased_prefix = "t#{ join_dependency.join_parts.size }" @tables = construct_tables.reverse end -- cgit v1.2.3