MomAndDad MomAndDad - 5 months ago 30
PHP Question

when magento sql is executed while using collection

I am using Magento collection. I have a question about a filter.
If I execute following PHP code, when does SQL get executed?

$xxx_collection = Mage::getModel('modulename/xxx')->getCollection();
$xxx_collection->getSelect()->limit($limit, $offset);
$xxx_collection->addFieldToFilter('user', $customerData->getId())->addFieldToFilter('xxx_id', 0);

The last line(filter code) will execute SQL?
What about the second (limit code) line?
If I don't use third line(addFieldToFilter), then the second line will execute SQL?

I am asking this question because I don't want my Magento to execute SQL twice. it will make overhead.


Change your code as below code

$mapInfo_collection = Mage::getModel('mapeditor/map')->getCollection();
$mapInfo_collection->addFieldToFilter('owner',$customerData->getId())->addFieldToFilter('parent_map_id', 0);
$mapInfo_collection->getSelect()->limit($limit, $offset);