Delete multiple entities by id Cakephp3

MontrealDevOne picture MontrealDevOne · Jul 7, 2015 · Viewed 8.4k times · Source

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 )
}

Answer

Alex Stallen picture Alex Stallen · Jul 7, 2015

This should work

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

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