/**
  * On delete of a model, check there are embedded media items bound to it and delete them
  *
  * @param CEvent $event
  */
 public static function onBeforeActiveRecordDelete($event)
 {
     $model = $event->sender->className();
     $pk = $event->sender->getPrimaryKey();
     // Check if primary key exists and is not array (multiple pk)
     if ($pk !== null && !is_array($pk)) {
         foreach (EmbeddedMedia::find()->where(['object_id' => $pk, 'object_model' => $model])->all() as $file) {
             $file->delete();
         }
     }
 }