Permalink
Browse files

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
  • Loading branch information...
1 parent 6141d0c commit 8e1b363167c22adcf75e3454dc8bfd34b5801d79 @tenderlove tenderlove committed Oct 3, 2013
@@ -137,8 +137,7 @@ def build(associations, parent = join_parts.last, join_type = Arel::InnerJoin)
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 @@ def remove_uniq_by_reflection(reflection, records)
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)
@@ -29,13 +29,13 @@ class JoinAssociation < JoinPart # :nodoc:
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

0 comments on commit 8e1b363

Please sign in to comment.