Search code examples
magentomodelmagento-1.9.1

Magento model can't delete row


I m trying to delete my db table row using below code from observer. but can't delete it gives error in system log

 Some transactions have not been committed or rolled back

$customFieldValue =  $this->_getRequest()->getPost();
             //$groupCodeArray = $customFieldValue['product']['customer_group_ids'];

             $DataCollectionDel = Mage::getModel('customerspecificproduct/customerspecificproduct')->getCollection()->addFieldToFilter(
                'product_ids',
                array(
                    'eq'=>$product->getId()
                )
            )->addFieldToFilter(
                'group_id',
                array(
                    'notnull'=>true,
                )
            );


            if($DataCollectionDel){
             foreach($DataCollectionDel as $data){
                    $deleteRow = Mage::getModel('customerspecificproduct/customerspecificproduct')->load($data->getId())->delete();

                }
             }exit;

Solution

  • I found solution myself

    $DataCollectionDel = Mage::getModel('customerspecificproduct/customerspecificproduct')->getCollection()->addFieldToFilter(
                    'product_ids',
                    array(
                        'eq'=>$product->getId()
                    )
                )->addFieldToFilter(
                    'group_id',
                    array(
                        'notnull'=>true,
                    )
                );
    
    
    
                 try{
                    if($DataCollectionDel){
                 foreach($DataCollectionDel as $data){
                        $data->delete();
                    }
                 }