0

I'm using magento 2, I created some tables that I fill with entries then I want to delete all those entries at once. I want the solution to use Magento repository abd without using a foreach. Something like deleteAll for example.

Thanks alot.

3
  • You can delete by database Jun 30, 2020 at 18:23
  • I'm looking for a way to PROGRAMATICALLY delete records not manually. Jun 30, 2020 at 18:32
  • please check my below answer maybe help you. Jul 1, 2020 at 5:24

1 Answer 1

2

If you need to delete all the data row from the database table then you can be used the below code to truncate the table using the model.

$connection = $model->getCollection()->getConnection();
$tableName = $model->getCollection()->getMainTable();
$connection->truncateTable($tableName);

I hope this is helpful to you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.