query_attribute.rb 549 字节
Newer Older
1 2
# frozen_string_literal: true

3
require "active_record/attribute"
S
Sean Griffin 已提交
4 5 6

module ActiveRecord
  class Relation
7
    class QueryAttribute < Attribute # :nodoc:
S
Sean Griffin 已提交
8 9 10 11 12 13 14 15 16 17 18
      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
19 20 21 22 23

      def nil?
        !value_before_type_cast.is_a?(StatementCache::Substitute) &&
          (value_before_type_cast.nil? || value_for_database.nil?)
      end
S
Sean Griffin 已提交
24 25 26
    end
  end
end