Question

I have seen an interesting thing in model configuration in config.xml. I was unknown about the tags <deprecatedNode> in model class declaration and is want to know about this tags.

In a custom extension we just need this type of model class declaration..

 <models>
            <[module]>
                <class>[Namespace]_[Module]_Model</class>
                <resourceModel>[module]_mysql4</resourceModel>
            </[module]>
            <[module]_mysql4>
                <class>[Namespace]_[Module]_Model_Mysql4</class>
                <entities>
                    <[module]>
                        <table>[module]</table>
                    </[module]>
                </entities>
            </[module]_mysql4>
        </models>

Reference -http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table

But in magento existing modules like Wishlist 's config.xml define model with deprecatedNode and resourceModel declare with this pattern

<wishlist>
                <class>Mage_Wishlist_Model</class>
                <resourceModel>wishlist_resource</resourceModel>
            </wishlist>
<wishlist_resource>

    <class>Mage_Wishlist_Model_Resource</class>
                <deprecatedNode>wishlist_mysql4</deprecatedNode>
                <entities>
                    <wishlist>
                        <table>wishlist</table>
                    </wishlist>
                    <item>
                        <table>wishlist_item</table>
                    </item>
                    <item>
                        <table>wishlist_item</table>
                    </item>
                    <item_option><table>wishlist_item_option</table></item_option>
                </entities>
            </wishlist_resource>

WHY THIS TYPE OF CODE USED IN MAGENTO

 <resourceModel>wishlist_resource</resourceModel>
                </wishlist>

                <wishlist_resource>

                    <class>Mage_Wishlist_Model_Resource</class>
                    <deprecatedNode>wishlist_mysql4</deprecatedNode>
Was it helpful?

Solution

In versions previous to 1.6 the <resourceModel> node usually had this name: [module]_mysql4.
Starting with version 1.6 Magento supports (in theory) other types of databases not just mysql. So the resource model name changed to wishlist_resource.
but in order to make old extensions that might rewrite the some resource model still work, this deprecatedNode was introduced.
If a model or a resource model is not found using the [module]_resource tag then Magento looks for it using the deprecatedNode value.
Take a look at these methods:
Mage_Core_Model_Resource::getEntity

public function getEntity($model, $entity)
{
    $modelsNode = Mage::getConfig()->getNode()->global->models;
    $entityConfig = $modelsNode->$model->entities->{$entity};

    /**
     * Backwards compatibility for pre-MMDB extensions.
     * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
     * to keep name of previously used nodes, that still may be used by non-updated extensions.
     */
    if (isset($modelsNode->$model->deprecatedNode)) {
        $deprecatedNode = $modelsNode->$model->deprecatedNode;
        if (isset($modelsNode->$deprecatedNode->entities->$entity)) {
            $entityConfig = $modelsNode->$deprecatedNode->entities->$entity;
        }
    }

    return $entityConfig;
}

and Mage_Core_Model_Config::getGroupedClassName

public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
{
    ....
    $className = null;
    if (isset($config->rewrite->$class)) {
        $className = (string)$config->rewrite->$class;
    } else {
        /**
         * Backwards compatibility for pre-MMDB extensions.
         * In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
         * to keep name of previously used nodes, that still may be used by non-updated extensions.
         */
        if ($config->deprecatedNode) {
            $deprecatedNode = $config->deprecatedNode;
            $configOld = $this->_xml->global->{$groupType.'s'}->$deprecatedNode;
            if (isset($configOld->rewrite->$class)) {
                $className = (string) $configOld->rewrite->$class;
            }
        }
    }
    ....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top