From 4ddd3046aaa81532510f91bfc3ee8c02854ec666 Mon Sep 17 00:00:00 2001 From: Ray Zane Date: Sun, 17 Feb 2019 14:48:19 -0500 Subject: [PATCH] Find the table --- lib/baby_squeel/join_dependency.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/baby_squeel/join_dependency.rb b/lib/baby_squeel/join_dependency.rb index 249f85c..21b1ede 100644 --- a/lib/baby_squeel/join_dependency.rb +++ b/lib/baby_squeel/join_dependency.rb @@ -35,8 +35,13 @@ def initialize(relation) # a list (in order of chaining) of associations and finding # the respective JoinAssociation at each level. def find_alias(associations) - table = find_join_association(associations).table - reconstruct_with_type_caster(table, associations) + join_association = find_join_association(associations) + + if join_association.table + join_association.table + else + join_association.base_klass.arel_table + end end private @@ -63,16 +68,6 @@ def reflections_equal?(a, b) def comparable_reflection(reflection) [*reflection.parent_reflection].last || reflection end - - # Active Record 5's AliasTracker initializes Arel tables - # with the type_caster belonging to the wrong model. - # - # See: https://github.com/rails/rails/pull/27994 - def reconstruct_with_type_caster(table, associations) - return table if ::ActiveRecord::VERSION::MAJOR < 5 - type_caster = associations.last._scope.type_caster - ::Arel::Table.new(table.name, type_caster: type_caster) - end end end end