Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete multiple entities by id Cakephp3

Tags:

cakephp-3.0

Is there a more efficient way of deleting multiple entities by id

$data = $this->request->data ['missing_lexicon_id'];
foreach ( $data as $id ) {
    $missingLexicon = $this->MissingLexicons->get ( $id );
    $this->MissingLexicons->delete ( $missingLexicon )
}
like image 668
MontrealDevOne Avatar asked Jul 07 '15 02:07

MontrealDevOne


1 Answers

This should work

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

Where $keys is an array with the ids to be deleted.

like image 68
Alex Stallen Avatar answered Sep 25 '22 07:09

Alex Stallen