From 217aedf1bf4255696c4f95976ee5056054dc9231 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 9 Oct 2013 11:23:45 -0700 Subject: push parent up to the superclass We always want a linked list back to the root node. --- .../active_record/associations/join_dependency/join_association.rb | 7 +------ .../lib/active_record/associations/join_dependency/join_base.rb | 4 ++++ .../lib/active_record/associations/join_dependency/join_part.rb | 7 ++++++- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record') 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 f6a04ef9f1..e2ac892e71 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -9,10 +9,6 @@ module ActiveRecord # 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 @@ module ActiveRecord 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 diff --git a/activerecord/lib/active_record/associations/join_dependency/join_base.rb b/activerecord/lib/active_record/associations/join_dependency/join_base.rb index c689d06594..c90ae80e4a 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_base.rb +++ b/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 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 e27beb3b6f..3e9bdbfbab 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_part.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_part.rb @@ -10,6 +10,10 @@ module ActiveRecord 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. @@ -17,8 +21,9 @@ module ActiveRecord 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 = [] -- cgit v1.2.3