0

我正在尝试使用来自观察者的以下代码删除我的数据库表行。但不能删除它在系统日志中给出错误

 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;
4

2 回答 2

0

我自己找到了解决方案

$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();
                }
             }
于 2015-01-09T11:10:00.100 回答
0

我找到了解决方案:3 没有getCollection()。模型

 public function deleteByCondition($itemId,$vendor)
    {
        return $this->getResource()->deleteByCondition($itemId,$vendor);
    }

资源模型

  public function deleteByCondition($itemId,$vendor)
    {
        $table = $this->getMainTable();
        $where = array();
        $where[] =  $this->_getWriteAdapter()->quoteInto('item_id = ?',$itemId);
        $where[] =  $this->_getWriteAdapter()->quoteInto("vendor = ? ", $vendor);
        $result = $this->_getWriteAdapter()->delete($table,$where);
        return $result;
    }
于 2015-07-31T07:44:05.443 回答