load() 如何在 Magento 1.9.2 的 EAV 模型中工作?

How load() works in EAV model in Magento 1.9.2?

$product = Mage::getModel('catalog/product')->load($this->getProductId());

load() 将进入 Mage_Core_Model_Abstract inside load() 函数,

public function load($id, $field=null)
{
    $this->_beforeLoad($id, $field);
    $this->_getResource()->load($this, $id, $field);
    $this->_afterLoad();
    $this->setOrigData();
    $this->_hasDataChanges = false;
    return $this;
}

现在这应该转到抽象 class Mage_Catalog_Model_Resource_Abstract 扩展 Mage_Eav_Model_Entity_Abstract 定义加载过程的地方:

public function load($object, $entityId, $attributes = array())
    {
        Varien_Profiler::start('__EAV_LOAD_MODEL__');
        /**
         * Load object base row data
         */
        $select  = $this->_getLoadRowSelect($object, $entityId);
        $row     = $this->_getReadAdapter()->fetchRow($select);

        ...

        if (empty($attributes)) {
            $this->loadAllAttributes($object);
        } else {
            foreach ($attributes as $attrCode) {
                $this->getAttribute($attrCode);
            }
        }

        $this->_loadModelAttributes($object);

        ...
    } 

可是我怎么也看不懂

$this->_getResource()->load($this, $id, $field); in Mage_Core_Model_Abstract

连接到摘要 class Mage_Catalog_Model_Resource_Abstract???

因为 load($this, $id, $field) 将要 abstract class Mage_Core_Model_Resource_Db_Abstract extends Mage_Core_Model_Resource_Abstract :

public function load(Mage_Core_Model_Abstract $object, $value, $field = null)
{
    if (is_null($field)) {
        $field = $this->getIdFieldName();
    }

    $read = $this->_getReadAdapter();
    if ($read && !is_null($value)) {
        $select = $this->_getLoadSelect($field, $value, $object);
        $data = $read->fetchRow($select);

        if ($data) {
            $object->setData($data);
        }
    }

    $this->unserializeFields($object);

请帮帮我。

产品模型中有_construct方法(catalog/product)。创建对象时会触发此方法。它显示要使用的资源模型:

$this->_init('catalog/product');

接下来在load方法中的Mage_Core_Model_Abstract中,有一个表达式$this->_getResource()。它可以带回 class 的对象 Mage_Catalog_Model_Resource_Product(它又继承自 Mage_Catalog_Model_Resource_Abstract)。

基本上,每个模型都可以有自己的资源模型 class。