Module: TypedEAV::ColumnMapping

Extended by:
ActiveSupport::Concern
Included in:
Field::Base
Defined in:
lib/typed_eav/column_mapping.rb

Overview

Maps field types to their native database column on the values table.

This is the core concept borrowed from Relaticle’s hybrid EAV: instead of serializing everything into a jsonb blob, each value type gets its own column so the database can natively index, sort, and enforce constraints.

Usage in field type classes:

class TypedEAV::Field::Integer < TypedEAV::Field::Base
  value_column :integer_value
end

The value model reads this to know which column to read/write. The query builder reads this to know which column to filter on. ActiveRecord handles all type casting automatically via the column’s registered ActiveRecord::Type.

Constant Summary collapse

DEFAULT_OPERATORS_BY_COLUMN =
{
  boolean_value: %i[eq not_eq is_null is_not_null],
  string_value: %i[eq not_eq contains not_contains starts_with ends_with is_null is_not_null],
  text_value: %i[eq not_eq contains not_contains starts_with ends_with is_null is_not_null],
  integer_value: %i[eq not_eq gt gteq lt lteq between is_null is_not_null],
  decimal_value: %i[eq not_eq gt gteq lt lteq between is_null is_not_null],
  date_value: %i[eq not_eq gt gteq lt lteq between is_null is_not_null],
  datetime_value: %i[eq not_eq gt gteq lt lteq between is_null is_not_null],
  json_value: %i[contains is_null is_not_null],
}.freeze
FALLBACK_OPERATORS =
%i[eq not_eq is_null is_not_null].freeze