For a homepage I am getting data like this from my module's table:


I wonder if this is the best thing performance wise. There are only 6 rows in that table. Would it be better to load it like this:

for($i = 1; $i < 7; $i++){


2 Answers 2


I'd say none of them.

Depending on what you need to achieve I would use collection without loading model and selecting only the attributes you need.

Example: I want to retrieve only name and description of the products with ID: 1,2,3,4,5,6 and 7:

$collection = Mage::getResourceModel('catalog/product_collection')

foreach ($collection as $product)
    echo $product->getName();
    echo $product->getDescription();

Always try to avoid loading entire object, especially in a loop.


Loading a full object like Mage::getModel('my_module')->load($i) takes a lot of time.

It is always a good idea to use the collection model Mage::getModel('my_module')->getCollection() instead of loading the full model for better performance.

Collection models always get data from a single query but every call of load() makes a new select query, so it's best to use getCollection().

Calling getData() at Mage::getModel('my_module')->getCollection(); is not a good idea. Use for loops for getting data.

And filter the collection by AddAttributeToFilter() (for EAV model) or AddFiledToFilter() (for flat table).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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