This is a code snippet from app/code/core/Mage/Catalog/etc/config.xml.


We can create Mage_Catalog_Model_Porduct object as

$model = Mage::getModel('catalog/product');

Same way can create the resource model object as follows.

$resourceModel = Mage::getModel('catalog_resource/product');

I know basically there's already a function as Mage::getResourceModel();. Example: Mage::getResourceModel('catalog/product');

But this way is also works fine.

Can anyone explain why not using Mage::getModel() to get the resource model object ? Any suggestions will be appreciated.


This is just my opinion so feel free to challange it, but I thing it's because in theory you can change the resource model class. For example I can add in my own module this:


If I were to use Mage::getModel('catalog_resource/product') I would get and instance of the original class because in the config DOM the declaration still exists.
but by calling Mage::getResourceModel('catalog/product') now I get and instance of my new class.
So I can conclude that the reason it 'extensibility'.
An other reason could be to keep a consistency.
If you call Mage::getModel($someParam) you will get the corresponding resource model by using the same parameter : $someParam.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.