Module: TypedEAV::HasTypedEAV
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/typed_eav/has_typed_eav.rb,
lib/typed_eav/has_typed_eav/instance_methods.rb
Overview
Include this in any ActiveRecord model to give it typed custom fields.
class Contact < ApplicationRecord
has_typed_eav
end
class Contact < ApplicationRecord
has_typed_eav scope_method: :tenant_id
end
This gives you:
# Reading/writing values
contact.typed_values # => collection
contact.initialize_typed_values # => builds missing values with defaults
contact.typed_eav_attributes = [...] # => bulk assign via nested attributes
# Querying (the good stuff)
Contact.where_typed_eav(
{ name: "age", op: :gt, value: 21 },
{ name: "status", op: :eq, value: "active" }
)
# Or the short form with a hash:
Contact.with_field("age", :gt, 21)
Contact.with_field("status", "active") # :eq is default
## Architecture (ADR-0002, 0.3.0 refactor)
This file holds the macro entry + macro-time guards. Per-record API lives in ‘TypedEAV::HasTypedEAV::InstanceMethods`. Class-level query orchestration lives in `TypedEAV::EntityQuery` (extended onto the host class), which delegates the heavy lifting to `TypedEAV::FilterQuery` (where_typed_eav) and `TypedEAV::BulkRead` (typed_eav_hash_for). `bulk_set_typed_eav_values` continues to delegate to `TypedEAV::BulkWrite`.
Defined Under Namespace
Modules: InstanceMethods