Working with EAV Model in Magento seems to be a quite complicated issue but you can totally make it easier with our new series of tutorials. My article today will start with some main concepts of EAV and take just a little time of you, so keep reading to broaden your knowledge.

1. Definition of EAV

According to Wikipedia: Entity-Attribute-Value model (EAV), also known as object-attribute-value model and open schema is a data model that is used in circumstances where the number of attributes (properties, parameters) that can be used to describe a thing (an “entity” or “object”) is potentially very vast, but the number that will actually apply to a given entity is relatively modest. In mathematics, this model is known as a sparse matrix.

The main features of EAV can be summarized as follows:

• EAV is a data model describing the organization of data

• Display the data of an object or entity

• Ability to expand the attribute set without changing the table structure

• Flexibility in storing data

• Suitable to entities having different attribute sets

2. Description of the EAV hierarchy structure

The EAV hierarchy structure includes these components:

• Entity: Lines in this table are displayed objects of an entity

• Attribute: Attributes of the object are lines in this table

• Value: Lines in this table contain the attribute values of objects

For instance, the object which is the users is stored as below:

3. How EAV data storage works in Magento

The EAV data storage in Magento seems quite complicated with the separated data for each store. There are some data storage tables:

  • EAV entity type: stores the entity type including the information of model for the entity or the default attribute set
  • EAV entity: Contains an eav_entity table storing objects of a certain entity type
  • EAV entity attribute: Attributes are divided into groups (one group may have a lot of attributes and one attribute may be in a lot of group). An attribute set includes the number of group. An object has an attribute set.
  • EVA entity value: Magento optimizes the data storage by providing value tables corresponding to the data types such as: eav_entity_datetime, eav_entity_varchar, eav_entity_int…

4. EAV data access process in Magento

Taking the EAV data out requires querying multiple tables continuously. Therefore, the data mapping will be implemented on multiple databases by models.

Reading data: To read the data from the database to the object, the model takes these steps:

  • Read the data from the main table or the entity table
  • Identify the attribute set of the object
  • Read the values of the attribute for the object
  • Change the value of the attribute (through the attrubute’s backend_model)
  • Map data to the object

Write data: The process of writing the EAV object’s data to the database is as below:

  • Take mapping data of the object
  • Change the value of the attribute (through the attrubute’s backend_model)
  • Save the data to the main table or the entity table
  • Save the data to the value attribute table

The further knowledge of EAV model in Magento will  continue being introduced in our next posts. See you again! 😉

 

Author

Why Magestore? We believe in building a meaningful & long-term relationship with you.

2 Comments

  1. Thanks for this tutorial. I some question.
    What does mean by “Take mapping data of the object”.
    Mapping in which table??

    2. Some fields in eav_entity_type table
    entity_model
    attribute_model
    does it describe the model of MVC?
    and what is the backend model??

    Thanks in advance

Write A Comment