Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用magento ORM中的collection删除数据?_Magento - Fatal编程技术网

如何使用magento ORM中的collection删除数据?

如何使用magento ORM中的collection删除数据?,magento,Magento,现在我正在删除数据,如 $deleteCCL = Mage::getModel('crossdata/customccitem'); $deleteCCL->load($itemId); $deleteCCL->delete(); 是否有任何方法可以使用收集来删除数据,如: $rcc = Mage::getModel('crossdata/customccitem')->getCollection()->delete(); ? 非常感谢 Balan没有方便

现在我正在删除数据,如

  $deleteCCL = Mage::getModel('crossdata/customccitem');
  $deleteCCL->load($itemId);
  $deleteCCL->delete();
是否有任何方法可以使用收集来删除数据,如:

$rcc = Mage::getModel('crossdata/customccitem')->getCollection()->delete();
?

非常感谢


Balan

没有方便的组删除功能,因此要么将其添加到收藏中,要么直接执行

foreach ($rcc as $ccitem) {
    $ccitem->delete();
}

要在集合中实现删除功能,必须向集合类或集合继承自的自定义抽象类添加新方法

示例:

public function delete()
{
    foreach ($this->getItems() as $key => $item) {
        $item->delete();
        unset($this->_items[$key]);
    }

    return $this;
}

Mage\u Eav\u Model\u Entity\u Collection\u Abstract
(扩展了
Varien\u Data\u Collection\u Db
)为集合提供了一种
delete()
方法(如果您有能力扩展它)

但是,它的实现与您的基本相同:

/**
 * Delete all the entities in the collection
 *
 * @todo make batch delete directly from collection
 */
public function delete()
{
    foreach ($this->getItems() as $k=>$item) {
        $this->getEntity()->delete($item);
        unset($this->_items[$k]);
    }
    return $this;
}

多亏了@leek,我的工作开始了:

foreach( $collection as $item )
    if( <<logic>> ) $collection->getEntity()->delete( $item );
foreach($collection as$item)
if()$collection->getEntity()->delete($item);

但这将分别删除每个。我们难道不想通过管道将任意集合的SQL传输到DELETE中,这样我们就可以一下子将它们全部删除吗?@sparksoft你是对的,这就是为什么我最初说你需要“将[group DELETE]添加到你的集合中”。注意:RTF所以正确回答:)我今天实现了这一点,但并不像我希望的那样一般。我想做的是实现一个delete方法,您可以将任意$collection传递到该方法中。但是我不太清楚如何做b/c adapter delete方法只需要一个$where参数,您需要传入一个SQL代码段,其中可能包括where's、join's、have's、group's等。喜欢docblock中的
@todo