aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-12-29 11:16:16 -0700
committerSean Griffin <sean@thoughtbot.com>2014-12-29 11:16:16 -0700
commit7931c96338353adc0ebfc780769ef3cd06ab0d79 (patch)
tree9bc3ba2a26b385dcb7d79ca1d57f24366be92f52 /activerecord/lib/active_record/associations
parent848cba13bd8a1fd7445458160a15dbf175c4c61d (diff)
downloadrails-7931c96338353adc0ebfc780769ef3cd06ab0d79.tar.gz
rails-7931c96338353adc0ebfc780769ef3cd06ab0d79.tar.bz2
rails-7931c96338353adc0ebfc780769ef3cd06ab0d79.zip
Pass a type caster when aliasing tables for joins
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/alias_tracker.rb6
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb3
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb8
3 files changed, 11 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb
index 0c3234ed24..f9c9f8afda 100644
--- a/activerecord/lib/active_record/associations/alias_tracker.rb
+++ b/activerecord/lib/active_record/associations/alias_tracker.rb
@@ -56,11 +56,11 @@ module ActiveRecord
@connection = connection
end
- def aliased_table_for(table_name, aliased_name)
+ def aliased_table_for(table_name, aliased_name, **table_options)
if aliases[table_name].zero?
# If it's zero, we can have our table_name
aliases[table_name] = 1
- Arel::Table.new(table_name)
+ Arel::Table.new(table_name, table_options)
else
# Otherwise, we need to use an alias
aliased_name = connection.table_alias_for(aliased_name)
@@ -73,7 +73,7 @@ module ActiveRecord
else
aliased_name
end
- Arel::Table.new(table_name).alias(table_alias)
+ Arel::Table.new(table_name, table_options).alias(table_alias)
end
end
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 0ac10531e5..53f65920e1 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -66,7 +66,8 @@ module ActiveRecord
chain.map do |reflection|
alias_tracker.aliased_table_for(
table_name_for(reflection, klass, refl),
- table_alias_for(reflection, refl, reflection != refl)
+ table_alias_for(reflection, refl, reflection != refl),
+ type_caster: klass.type_caster,
)
end
end
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index 6c1c700d54..66e997c3c8 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -94,7 +94,7 @@ module ActiveRecord
#
def initialize(base, associations, joins)
@alias_tracker = AliasTracker.create(base.connection, joins)
- @alias_tracker.aliased_table_for(base.table_name, base.table_name) # Updates the count for base.table_name to 1
+ @alias_tracker.aliased_table_for(base.table_name, base.table_name, type_caster: base.type_caster) # Updates the count for base.table_name to 1
tree = self.class.make_tree associations
@join_root = JoinBase.new base, build(tree, base)
@join_root.children.each { |child| construct_tables! @join_root, child }
@@ -186,9 +186,13 @@ module ActiveRecord
def table_aliases_for(parent, node)
node.reflection.chain.map { |reflection|
+ if reflection.klass
+ type_caster = reflection.klass.type_caster
+ end
alias_tracker.aliased_table_for(
reflection.table_name,
- table_alias_for(reflection, parent, reflection != node.reflection)
+ table_alias_for(reflection, parent, reflection != node.reflection),
+ type_caster: type_caster,
)
}
end