Skip to content

Architecture

EAV data model, entity types, value tables, attribute sets and groups.

EAV Data Model

The Entity-Attribute-Value (EAV) pattern separates attribute storage from entity storage, allowing unlimited custom attributes without modifying the database schema. This flexibility comes at the cost of query complexity.

ENTITY TYPE (eav_entity_type)
| catalog_product, catalog_category, customer, customer_address
|
+-->
ATTRIBUTE SET (eav_attribute_set)
| | "Default", "Clothing", "Electronics"
| |
| +-->
ATTRIBUTE GROUP (eav_attribute_group)
| | "Product Details", "Images", "SEO"
| |
| +-->
ATTRIBUTE (eav_attribute)
| name, price, description, color...
|
+-->
ENTITY (entity-specific table)
| catalog_product_entity, customer_entity...
|
+-->
VALUES (typed value tables)
eav_entity_varchar, eav_entity_int...
Terminology

Entity Type: The "class" of entity (product, customer).
Attribute Set: A collection of attributes assigned to an entity.
Attribute Group: A tab within an attribute set for organization.
Attribute: A single property (name, color, price).

Value Tables by Type

EAV stores attribute values in separate tables based on data type. This allows proper indexing and type-specific operations. The backend_type column in eav_attribute determines which table stores the value.

VARCHAR
eav_entity_varchar
INT
eav_entity_int
DECIMAL
eav_entity_decimal
TEXT
eav_entity_text
DATETIME
eav_entity_datetime

Value Table Structure

All value tables share a common structure with store-scoped values:

// Common columns in all eav_entity_* value tables value_id // Primary key (auto-increment) entity_type_id // FK to eav_entity_type attribute_id // FK to eav_attribute store_id // FK to store (0 = default/admin) entity_id // FK to entity table (product_id, customer_id) value // The actual value (type varies by table) // Unique constraint: entity_id + attribute_id + store_id // This enables store-scoped attribute overrides
Static vs EAV Attributes

Attributes with backend_type='static' are stored directly in the entity table (e.g., sku in catalog_product_entity). This avoids JOINs for frequently accessed attributes.

Core Database Tables

eav_entity_type
Defines entity types and their configurations.
  • -> entity_type_id (PK)
  • -> entity_type_code (product, customer)
  • -> entity_model (resource model class)
  • -> attribute_model (custom attribute class)
  • -> entity_table (main entity table)
  • -> default_attribute_set_id
  • -> additional_attribute_table
eav_attribute
Attribute definitions with model references.
  • -> attribute_id (PK)
  • -> entity_type_id (FK)
  • -> attribute_code (unique per type)
  • -> backend_type (varchar/int/decimal/text/datetime/static)
  • -> backend_model (validation class)
  • -> frontend_model (display class)
  • -> frontend_input (text/select/multiselect/boolean)
  • -> source_model (options class)
  • -> is_required, is_user_defined, is_unique
eav_attribute_set
Groups of attributes for entity assignment.
  • -> attribute_set_id (PK)
  • -> entity_type_id (FK)
  • -> attribute_set_name
  • -> sort_order
eav_attribute_group
Tabs within attribute sets.
  • -> attribute_group_id (PK)
  • -> attribute_set_id (FK)
  • -> attribute_group_name
  • -> attribute_group_code
  • -> tab_group_code
  • -> sort_order
eav_entity_attribute
Links attributes to sets/groups.
  • -> entity_attribute_id (PK)
  • -> entity_type_id (FK)
  • -> attribute_set_id (FK)
  • -> attribute_group_id (FK)
  • -> attribute_id (FK)
  • -> sort_order
eav_attribute_option
Options for select/multiselect attributes.
  • -> option_id (PK)
  • -> attribute_id (FK)
  • -> sort_order
eav_attribute_option_value
Store-scoped option labels.
  • -> value_id (PK)
  • -> option_id (FK)
  • -> store_id (FK)
  • -> value (the label text)
eav_attribute_label
Store-scoped attribute labels.
  • -> attribute_label_id (PK)
  • -> attribute_id (FK)
  • -> store_id (FK)
  • -> value (the label text)

Attribute Model Pattern

Each attribute can have three types of associated models that control its behavior during save, load, and display operations.

Backend Model

Validates and transforms data before save. Examples: ArrayBackend, Datetime, Increment. Method: beforeSave(), afterSave(), validate()

Frontend Model

Formats values for display. Examples: Datetime (date formatting), Image (generates URLs). Method: getValue()

Source Model

Provides options for select/multiselect inputs. Examples: Boolean, Table, Config. Method: getAllOptions(), getOptionText()

Example: Creating a Custom Attribute

// In Setup/Patch/Data/AddCustomAttribute.php $eavSetup = $this->eavSetupFactory->create(); $eavSetup->addAttribute( Product::ENTITY, 'custom_attribute', [ 'type' => 'varchar', // backend_type 'label' => 'Custom Attribute', 'input' => 'select', // frontend_input 'source' => CustomSource::class, // source_model 'backend' => ArrayBackend::class, // backend_model 'required' => false, 'global' => ScopedAttribute::SCOPE_STORE, 'visible' => true, 'user_defined' => true, 'group' => 'General', ] );

Entity Type Configuration

Each entity type defines its storage configuration in eav_entity_type. This tells EAV how to load and save entities of that type.

// eav_entity_type row for products entity_type_id = 4 entity_type_code = 'catalog_product' entity_model = 'Magento\Catalog\Model\ResourceModel\Product' attribute_model = 'Magento\Catalog\Model\ResourceModel\Eav\Attribute' entity_table = 'catalog_product_entity' additional_attribute_table = 'catalog_eav_attribute' entity_attribute_collection = 'Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection' // Products use extended tables: // - catalog_eav_attribute extends eav_attribute with catalog-specific columns // - catalog_product_entity_* extends eav_entity_* for product values