1

load by Id

$data = Mage::getModel('module_name/model)->load($id);

or

//collection by filter

$data = Mage::getModel('module_name/model)->getCollection()->addFieldToFilter('id',$id);
1
  • Welcome to Magento SE. The question already has been asked, so I answered it in the duplicate linked above. TL;DR: It depends what you need because both give different results Commented Aug 20, 2016 at 19:59

1 Answer 1

1

The proper method to get single record : Mage::getModel('module_name/model)->load($id);

If you use getCollection() then it will load all the record of that particular table and then it will filter the record from all collection.

While load() will fetch only single record from that table.

4
  • Thanks for prompt reply. Is there any way to calculate load time of both queries in magento?
    – Vishal
    Commented Aug 20, 2016 at 6:49
  • Calling a collection does NOT load each item. Each record will be contained within the collection but ->load() is not called on each object and as such the object is not actually loaded. However, you are correct that loading a single record by ID is the most efficient way. Commented Aug 20, 2016 at 6:54
  • @Vishal you can use xdebug's profiler to determine memory and time calculations. Commented Aug 20, 2016 at 6:56
  • You can use this extension to get all query time detail. mgt-commerce.com/magento-developer-toolbar.html Commented Aug 20, 2016 at 6:56

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