2

I am validating an extension using ECG Sniffs and I get a warning 'getFirstItem does not limit the result of collection load to one item

Here is how I am trying to get default configured website.

$websites = Mage::getModel('core/website')
                    ->getCollection()
                    ->addFieldToFilter('is_default', 1);
$website = $websites->getFirstItem();

Here I try to replace $websites->getFirstItem() with $websites->getSelect()->limit() as per a suggestion but it gives another warning Data access method LIMIT detected outside of Resource Model

Can anybody please help me how to fix the warning?

P.S. I am neither magento nor PHP developer.

  • 1
    You dont have to replace $websites->getFirstItem(). Just add $websites->getSelect()->limit(1) before. Btw ... the warning will still appear. If you've limit the query to 1, you can use getLastItem() instead. – sv3n Dec 12 '17 at 10:52
  • 1
    @sv3n thanks. I ended up using $websites->setPageSize(1, 1)->getLastItem() – Amit Patel Dec 12 '17 at 11:23
  • @sv3n I also get Data load getParentIdsByChild() method detected in loop warning. I am fetching parent sku for each product in loop. Here is a reference question stackoverflow.com/a/11481143/517483. Any idea? – Amit Patel Dec 12 '17 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.