Magento模型无法删除行

时间:2015-01-08 07:44:36

标签: magento model magento-1.9.1

我试图使用来自observer的以下代码删除我的db表行。但无法删除它会在系统日志中出现错误

 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;

2 个答案:

答案 0 :(得分: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();
                }
             }

答案 1 :(得分: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;
    }