Skip to content
Browse files

push parent up to the superclass

We always want a linked list back to the root node.
  • Loading branch information...
1 parent 40ad439 commit 217aedf1bf4255696c4f95976ee5056054dc9231 @tenderlove tenderlove committed Oct 9, 2013
View
7 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -9,10 +9,6 @@ class JoinAssociation < JoinPart # :nodoc:
# The reflection of the association represented
attr_reader :reflection
- # A JoinBase instance representing the active record we are joining onto.
- # (So in Author.has_many :posts, the Author would be that base record.)
- attr_reader :parent
-
# What type of join will be generated, either Arel::InnerJoin (default) or Arel::OuterJoin
attr_accessor :join_type
@@ -25,11 +21,10 @@ class JoinAssociation < JoinPart # :nodoc:
delegate :options, :through_reflection, :source_reflection, :chain, :to => :reflection
def initialize(reflection, index, parent, join_type, alias_tracker)
- super(reflection.klass)
+ super(reflection.klass, parent)
@reflection = reflection
@alias_tracker = alias_tracker
- @parent = parent
@join_type = join_type
@aliased_prefix = "t#{ index }"
@tables = construct_tables.reverse
View
4 activerecord/lib/active_record/associations/join_dependency/join_base.rb
@@ -4,6 +4,10 @@ module ActiveRecord
module Associations
class JoinDependency # :nodoc:
class JoinBase < JoinPart # :nodoc:
+ def initialize(klass)
+ super(klass, nil)
+ end
+
def ==(other)
other.class == self.class &&
other.base_klass == base_klass
View
7 activerecord/lib/active_record/associations/join_dependency/join_part.rb
@@ -10,15 +10,20 @@ class JoinDependency # :nodoc:
class JoinPart # :nodoc:
include Enumerable
+ # A JoinBase instance representing the active record we are joining onto.
+ # (So in Author.has_many :posts, the Author would be that base record.)
+ attr_reader :parent
+
# The Active Record class which this join part is associated 'about'; for a JoinBase
# this is the actual base model, for a JoinAssociation this is the target model of the
# association.
attr_reader :base_klass, :children
delegate :table_name, :column_names, :primary_key, :arel_engine, :to => :base_klass
- def initialize(base_klass)
+ def initialize(base_klass, parent)
@base_klass = base_klass
+ @parent = parent
@cached_record = {}
@column_names_with_alias = nil
@children = []

0 comments on commit 217aedf

Please sign in to comment.
Something went wrong with that request. Please try again.