Method: ActiveRecord::Relation::QueryAttribute#initialize

Defined in:
activerecord/lib/active_record/relation/query_attribute.rb

#initializeQueryAttribute

Returns a new instance of QueryAttribute.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'activerecord/lib/active_record/relation/query_attribute.rb', line 8

def initialize(...)
  super

  # The query attribute value may be mutated before we actually "compile" the query.
  # To avoid that if the type uses a serializer we eagerly compute the value for database
  if value_before_type_cast.is_a?(StatementCache::Substitute)
    # we don't need to serialize StatementCache::Substitute
  elsif @type.serialized?
    value_for_database
  elsif @type.mutable? # If the type is simply mutable, we deep_dup it.
    @value_before_type_cast = @value_before_type_cast.deep_dup
  end
end