mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
5cb261af8e
Some apps would expect that type cast is not evaluated at relation build
time consistently.
Context:
b571c4f3f2 (r31015008)
https://github.com/rails/rails/pull/34303
And also this removes extra grouping on IN clause behaved as before.
68 lines
1.3 KiB
Ruby
68 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Arel # :nodoc: all
|
|
module Nodes
|
|
class HomogeneousIn < Node
|
|
attr_reader :attribute, :values, :type
|
|
|
|
def initialize(values, attribute, type)
|
|
@values = values
|
|
@attribute = attribute
|
|
@type = type
|
|
end
|
|
|
|
def hash
|
|
ivars.hash
|
|
end
|
|
|
|
def eql?(other)
|
|
super || (self.class == other.class && self.ivars == other.ivars)
|
|
end
|
|
alias :== :eql?
|
|
|
|
def equality?
|
|
true
|
|
end
|
|
|
|
def invert
|
|
Arel::Nodes::HomogeneousIn.new(values, attribute, type == :in ? :notin : :in)
|
|
end
|
|
|
|
def left
|
|
attribute
|
|
end
|
|
|
|
def table_name
|
|
attribute.relation.table_alias || attribute.relation.name
|
|
end
|
|
|
|
def column_name
|
|
attribute.name
|
|
end
|
|
|
|
def casted_values
|
|
type = attribute.type_caster
|
|
|
|
casted_values = values.map do |raw_value|
|
|
type.unchecked_serialize(raw_value) if type.serializable?(raw_value)
|
|
end
|
|
|
|
casted_values.compact!
|
|
casted_values
|
|
end
|
|
|
|
def fetch_attribute(&block)
|
|
if attribute
|
|
yield attribute
|
|
else
|
|
expr.fetch_attribute(&block)
|
|
end
|
|
end
|
|
|
|
protected
|
|
def ivars
|
|
[@attribute, @values, @type]
|
|
end
|
|
end
|
|
end
|
|
end
|