Magento Certified Developer GuideCategory: 4. DatabaseDescribe the collection interface (filtering/sorting/grouping)
Manish Prakash Staff asked 2 years ago

You can read about collection interface in detail here

Collection interface is defined at Mage_Core_Model_Resource_Collection_Abstract which extends Varien_Data_Collection_Db

Collection interface mainly provides a way to handle a group of models e.g

$collection = Mage::getModel('core/website')->getCollection();
$collection->addFieldToSelect('*');
$collection->addFieldToFilter('is_default',1);
$collection->setOrder('name', 'DESC');
//$collection->setOrder('rand()');
$collection->addOrder('name','DESC');
$collection->unshiftOrder('name');  //default is DESC
$collection->setPageSize(10);
$collection->count();
$collection->getAllIds();
echo $collection->getSelect();
$collection->load();
$collection->getSize();
$collection->getSelectCountSql();
$collection->printLogQuery();