I'm able to fetch the single items, or the whole tables via the $modelFactory->create()->load(ID) or $modelFactory->create()->getCollection()

Using the $modelFactory, how can I delete all the data fetched?

---- UPDATE ----

The code I'm using at the moment is the following one. I guess it's running a query per item, instead of doing one query for all the items, so I'm looking for a way to do it in one single shot.

$cleanup = $this->myModelFactory->create()->getCollection();
foreach($cleanup as $item) {
  • What's wrong with the way you're doing it now? – Daniel Black Nov 8 at 19:36
  • @DanielBlack is not wrong it's more something about performance. I expect that an SQL query will be run at each foreach recursion. So if for example $cleanup has 50 items, the foreach loop will generate 50 SQL delete query instead of one with all the items to delete. – Luigi T. Nov 8 at 20:32

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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