0

I have tried

$get_default_metal = Mage::getModel('custompricing/metaloptionsenabled')->getCollection()
->addFieldToFilter('product_id', $product_id)
->addFieldToFilter('store_id',0)
->addFieldToFilter('status',1)
->addFieldToFilter('isdefault',1)
->addFieldToSelect('metal_id')
->addFieldToSelect('ring_sizer')
->getFirstItem();  

=>

$sql = "select metal_id,ring_sizer from metal_options_enabled where store_id=0 and status=1 and isdefault=1";
Is this right?

6
  • just use echo $get_default_metal->getSelect()->__toString() to print the query of this collection
    – Amit Bera
    Jul 19, 2016 at 6:45
  • Fatal error: Call to a member function toString() on null - I am getting fatal error.
    – jassi
    Jul 19, 2016 at 6:50
  • echo $get_default_metal->getSelect(); will show you query Jul 19, 2016 at 7:00
  • __toString() need
    – Amit Bera
    Jul 19, 2016 at 7:01
  • first remove ->getFirstItem(); then use $get_default_metal->getSelect()->__toString() and use $get_default_metal->getFirstItem() get first item data of collection
    – Amit Bera
    Jul 19, 2016 at 7:02

2 Answers 2

2

First remove ->getFirstItem(); then use $get_default_metal->getSelect()->__toString() for print the query

and the add $get_default_metal->getFirstItem() get first item data of collection

0

getFirstItem(); gives you only first row.

for Print sql Query just write like this,

echo $get_default_metal->getSelect();

0

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.