Removing multiple objects by Cakephp3 id

Is there a more efficient way to delete multiple objects with id

$data = $this->request->data ['missing_lexicon_id']; foreach ( $data as $id ) { $missingLexicon = $this->MissingLexicons->get ( $id ); $this->MissingLexicons->delete ( $missingLexicon ) } 
+7
source share
2 answers

This should work

 $this->MissingLexicons->deleteAll(['MissingLexicons.column IN' => $keys]); 

Where $ keys is an array with identifiers to be deleted.

+5
source share

The most efficient way to delete multiple objects with deleteALL () .

 $this->MissingLexicons->deleteAll(['id IN' => $multiItemsArray]); 

OR

 $this->MissingLexicons->deleteAll(['id' => $multiItemsArray[]]); 

MissingLexicons = the name of your model.

$ multiItemsArray = Deleted id objects

More here

0
source share

All Articles