Magento EAV模型
在第一篇介绍Magento ORM的文章中,我们提到过Magento拥有两类模型。普通的模型及Entity Attribute Value(EAV)模型。这里首先搞清楚它们之前的一些关系。
所有的Magento模型都继承自Mage_Core_Model_Abstract/Varien_Object类链。真正区别普通模型和EAV模型的关键是该模型使用的模型资源(Model Resource)。尽管所有的资源类都继承自Mage_Core_Model_Resource_Abstract类,普通模型拥有继承自该类的子类Mage_Core_Model_Mysql4_Abstract,同时EAV模型拥有继承自该类的另外一个子类Mage_Eav_Model_Entity_Abstract。
为什么要这样设计呢?仔细想想,不难得出结论。作为终端程序员,你需要的只是如何与数据库交互的方法,而不用在意底层是如何实现的。
EAV模型
这里我们引用维基百科的定义,这段暂时就不翻译了,太多术语。
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.
在一个普通的数据库中,表中一般包含多列,像下表所示,
详细摘自:http://www.ruiwant.com/magento-for-dev-part-7-advanced-orm-entity-attribute-value.html
浙公网安备 33010602011771号