Best Practices for Getting Resource/Collection Models in Magento 1.9

best practicemagento-1.9programming

Which one is more correct:
Mage::getResourceModel() or
Mage::getModel('catalog/product')->getCollection()

I always use the first method unless I already have a model that I can call the getCollection on. I'm just wondering if there are any advantages/disadvantages to it.

Best Answer

The methods Mage_Core_Model_Abstract::getResource() and Mage_Core_Model_Abstract::getCollection() are just handy shortcuts if you want to get the resource model or collection for an existing model instance.

They eventually call Mage::getResourceModel(), so if you don't already have an instantiated model, the more straightforward way to instantiate a collection or resource model is to use Mage::getResourceModel() directly. The result is always the same.

Related Topic