aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_attribute.rb
blob: 5a9a7fd432d7e45ed9df124e2e6f2a02e142f227 (plain) (tree)
1
2
3
4
5
6
7

                             
                               


                   
                                              










                                             




                                                                    


       
# frozen_string_literal: true

require_relative "../attribute"

module ActiveRecord
  class Relation
    class QueryAttribute < Attribute # :nodoc:
      def type_cast(value)
        value
      end

      def value_for_database
        @value_for_database ||= super
      end

      def with_cast_value(value)
        QueryAttribute.new(name, value, type)
      end

      def nil?
        !value_before_type_cast.is_a?(StatementCache::Substitute) &&
          (value_before_type_cast.nil? || value_for_database.nil?)
      end
    end
  end
end