Sha256: a07c422f68f3f6914d7981d4346a1303434bcc532c21ec30cf36670fd018c118

Contents?: true

Size: 561 Bytes

Versions: 3

Compression:

Stored size: 561 Bytes

Contents

# frozen_string_literal: true

require "active_model/attribute"

module ActiveRecord
  class Relation
    class QueryAttribute < ActiveModel::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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-5.2.0.rc1 lib/active_record/relation/query_attribute.rb
activerecord-5.2.0.beta2 lib/active_record/relation/query_attribute.rb
activerecord-5.2.0.beta1 lib/active_record/relation/query_attribute.rb