Wednesday, February 23, 2011

What is Magento EAV?

EAV stands for Entity, Attribute and Value.

Now what is this EAV means? We know that there are several table used in magento lets say we have a table Customer, this table would have several fields like first name, last name, email ID etc. and the values like Ashok, Sharma, ashok@somthing.com respectively. Now lets relate it with this EAV structure, here customer is an entity which has several attribute firstname, lastname and email ID and at last Ashok, sharma ect are values for the attributes.

Lets get into it deeply, in general scenario if we have an ecommerce application it will have several tables lets take an example of product table it will have all the information of a product and there will be another table for categories etc. So what we see is all the information of a product is in one table.

This is what magento doesn't follow. In magento product information is spread into several table. The core table for product is catalog_product_entity, if you see this table it doesn’t have any information of product which you have entered from admin panel except SKU. Now to get all details of product you have to join all attribute to the product entity table, to get product attribute go to the table eav_attribute. If you closely see this table there are lot of attributes so to distinguish product attribute see the field entity_type_id, since each entity has its unique entity_type_id, using this you can get load the attributes of product.

Now you have both entity and attribute its time to get values of the attributes, values are also separated across several table like all the string type values will be stored in catelog_product_varchar table, price will be stored in catelog_product_entity_decimal tables and so on.

So what we come to know from above is that EAV is much more scalable than normal database structure, this mean if we have to add any new field in product we don’t have to change the database table structure, what we do we create an attribute for that and insert values for it.

Hope this will be helpful.

No comments:

Post a Comment