What does backend type static mean in Magento?

来源:互联网 发布:阿里云栖大会苏州 编辑:程序博客网 时间:2024/06/06 19:23

What does backend type static mean in Magento?

Abouta year ago, I noticed some category or product attributes, for example,sku, path, etc., were given backend type “static” in classMage_Catalog_Model_Resource_Eav_Mysql4_Setup. But I failed to find outwhat static meant here, or I did not know what the difference wasbetween static and datetime/decimal/int/text/varchar. All I knew atthat time was if I gave my user defined attribute a “static” type, theattribute values were stored in _varchar table.

Recently, I dived deeper into Magento EAV module. Now I can answer my question.

An entity can have some “static” attributes, whose values are storedin entity main table. Take sku for example, sku values are stored incatalog_product_entity table. Although sku is varchar type, its valuesare not stored in catalog_product_entity_varchar. Magento does notlookup catalog_product_entity_varchar for sku values because ineav_attribute table, sku backend type is defined as “static”.

It also explains why I can get sku values without add it to select, but I can not do the same with non static attributes.

view sourceprint?
1$collection = Mage::getModel('catalog/product')->getCollection();
2echo $collection->getFirstItem()->getSku();

It will output the sku.

view sourceprint?
1$collection = Mage::getModel('catalog/product')->getCollection();
2echo $collection->getFirstItem()->getName();

It will not output the name.

view sourceprint?
1$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name');
2echo $collection->getFirstItem()->getName();

Calling addAttributeToSelect is a must to retrieve non static attribute values.

For user defined attributes of existing entity, if I do not changethe structure of main entity table, even I specify backend as “static”in entity setup class, Magento has nowhere to store their values to butfallback to _varchar table.

原创粉丝点击