I have an issue in Magento 1, where the SQL query that is getting generated has the back tics wrongly placed.
This is a piece of the code that helps to provide the collection to the grid layout.
protected function _prepareCollection(){
$accountId = $this->getRequest()->getParam('id');
$collection = Mage::getResourceModel('testmodule/coupon_collection');
if (Mage::helper('testmodulecoupon')->isMultiProgram()
&& Mage::helper('core')->isModuleEnabled('Test_module')
){
$collection->getSelect()->joinLeft(
array('p' => $collection->getTable('testmodule/account')),
'main_table.program_id = p.program_id AND main_table.account_id = p.account_id',
array()
)->joinLeft(
array('r' => $collection->getTable('testmodule/program')),
'main_table.program_id = r.program_id',
array('status' => 'IF (main_table.program_id = 0, 1, IF(p.id AND r.use_coupon, 1, 0))')
);
} else {
$collection->addFieldToFilter('program_id', array('eq'=>0));
}
$collection->addFieldToFilter('main_table.account_id',$accountId);
$this->setCollection($collection);
return parent::_prepareCollection();
}
In the above code, this part of the line is generating the back tics wrongly.
array('status' => 'IF (main_table.program_id = 0, 1, IF(p.id AND r.use_coupon, 1, 0))')
This is part of SQL query that is generating.
(`IF (main_table`.`program_id = 0, 1, IF(p`.`id AND r`.`use_coupon, 1, 0))` = '1')
I was not able to find a proper solution to fix this. Can anyone help on this ? thanks