mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
1ac40f16c5
In Active Record internal, `arel_table` is not directly used but `arel_attribute` is used, since `arel_table` doesn't normalize an attribute name as a string, and doesn't resolve attribute aliases. For the above reason, `arel_attribute` should be used rather than `arel_table`, but most people directly use `arel_table`, both `arel_table` and `arel_attribute` are private API though. Although I'd not recommend using private API, `arel_table` is actually widely used, and it is also problematic for unscopeable queries and hash-like relation merging friendly, as I explained at #39863. To resolve the issue, this change moves Arel attribute normalization (attribute name as a string, and attribute alias resolution) into `arel_table`.
31 lines
748 B
Ruby
31 lines
748 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Arel # :nodoc: all
|
|
module Nodes
|
|
class TableAlias < Arel::Nodes::Binary
|
|
alias :name :right
|
|
alias :relation :left
|
|
alias :table_alias :name
|
|
|
|
def [](name)
|
|
relation.is_a?(Table) ? relation[name, self] : Attribute.new(self, name)
|
|
end
|
|
|
|
def table_name
|
|
relation.respond_to?(:name) ? relation.name : name
|
|
end
|
|
|
|
def type_cast_for_database(attr_name, value)
|
|
relation.type_cast_for_database(attr_name, value)
|
|
end
|
|
|
|
def type_for_attribute(name)
|
|
relation.type_for_attribute(name)
|
|
end
|
|
|
|
def able_to_type_cast?
|
|
relation.respond_to?(:able_to_type_cast?) && relation.able_to_type_cast?
|
|
end
|
|
end
|
|
end
|
|
end
|