Skip to main content
Add content to improve answer
Source Link
Msquare
  • 9.3k
  • 7
  • 27
  • 68

Create a function in your ResourceModel

Create a function in your resourceModel like thisapp\code\Module\Namespace\Model\ResourceModel

Inventory.php

<?php

namespace Module\Namespace\Model\ResourceModel;

class Inventory extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
     protected function _construct()
     {
          $this->_init('your table name', 'primary key column name');
     }
    public function truncateTable()
        {
            if ($this->getConnection()->getTransactionLevel() > 0) {
                $this->getConnection()->delete($this->getMainTable());
            } else {
                $this->getConnection()->truncateTable($this->getMainTable());
            }
    
            return $this;
        }
}

and call this function from any file in your custom module. This must delete the table related to the resource.

And call this function from any file in your custom module. This must delete the table related to the resource.

Create a function in your resourceModel like this

namespace Module\Namespace\Model\ResourceModel;

class Inventory extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    public function truncateTable()
        {
            if ($this->getConnection()->getTransactionLevel() > 0) {
                $this->getConnection()->delete($this->getMainTable());
            } else {
                $this->getConnection()->truncateTable($this->getMainTable());
            }
    
            return $this;
        }
}

and call this function from any file in your custom module. This must delete the table related to the resource.

Create a function in your ResourceModel

app\code\Module\Namespace\Model\ResourceModel

Inventory.php

<?php

namespace Module\Namespace\Model\ResourceModel;

class Inventory extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
     protected function _construct()
     {
          $this->_init('your table name', 'primary key column name');
     }
    public function truncateTable()
        {
            if ($this->getConnection()->getTransactionLevel() > 0) {
                $this->getConnection()->delete($this->getMainTable());
            } else {
                $this->getConnection()->truncateTable($this->getMainTable());
            }
    
            return $this;
        }
}

And call this function from any file in your custom module. This must delete the table related to the resource.

Source Link

Create a function in your resourceModel like this

namespace Module\Namespace\Model\ResourceModel;

class Inventory extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
    public function truncateTable()
        {
            if ($this->getConnection()->getTransactionLevel() > 0) {
                $this->getConnection()->delete($this->getMainTable());
            } else {
                $this->getConnection()->truncateTable($this->getMainTable());
            }
    
            return $this;
        }
}

and call this function from any file in your custom module. This must delete the table related to the resource.