aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency/join_association.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency/join_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb40
1 files changed, 10 insertions, 30 deletions
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 3af613d2d1..191d430636 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -4,48 +4,28 @@ module ActiveRecord
module Associations
class JoinDependency # :nodoc:
class JoinAssociation < JoinPart # :nodoc:
- include JoinHelper
-
# The reflection of the association represented
attr_reader :reflection
- # What type of join will be generated, either Arel::InnerJoin (default) or Arel::OuterJoin
- attr_accessor :join_type
-
- # These implement abstract methods from the superclass
- attr_reader :aliased_prefix
-
- attr_reader :tables
- attr_reader :alias_tracker
+ attr_accessor :tables
- delegate :options, :through_reflection, :source_reflection, :chain, :to => :reflection
-
- def initialize(reflection, index, parent, join_type, alias_tracker)
- super(reflection.klass, parent)
+ def initialize(reflection, children)
+ super(reflection.klass, children)
@reflection = reflection
- @alias_tracker = alias_tracker
- @join_type = join_type
- @aliased_prefix = "t#{ index }"
- @tables = construct_tables.reverse
+ @tables = nil
end
- def parent_table_name; parent.table_name; end
- alias :alias_suffix :parent_table_name
-
def match?(other)
return true if self == other
super && reflection == other.reflection
end
- def join_constraints
+ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scope_chain, chain)
joins = []
- tables = @tables.dup
-
- foreign_table = parent.table
- foreign_klass = parent.base_klass
+ tables = tables.reverse
- scope_chain_iter = reflection.scope_chain.reverse_each
+ scope_chain_iter = scope_chain.reverse_each
# The chain starts with the target table, but we want to end with it here (makes
# more sense in this context), so we reverse
@@ -68,7 +48,7 @@ module ActiveRecord
if item.is_a?(Relation)
item
else
- ActiveRecord::Relation.create(klass, table).instance_exec(self, &item)
+ ActiveRecord::Relation.create(klass, table).instance_exec(node, &item)
end
end
@@ -88,7 +68,7 @@ module ActiveRecord
constraint = constraint.and rel.arel.constraints
end
- joins << join(table, constraint)
+ joins << table.create_join(table, table.create_on(constraint), join_type)
# The current table in this iteration becomes the foreign table in the next
foreign_table, foreign_klass = table, klass
@@ -126,7 +106,7 @@ module ActiveRecord
end
def table
- tables.last
+ tables.first
end
def aliased_table_name