/**
  * Updates an existing SourceMessage model.
  *
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  * @throws \yii\base\ErrorException
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $relatedModels = $model->getMessagesMap(true);
     if ($model->load(Yii::$app->request->post())) {
         Message::loadMultiple($relatedModels, Yii::$app->request->post());
         foreach ($relatedModels as $relatedModel) {
             if (!$relatedModel->save()) {
                 throw new ErrorException(Yii::t('app', 'Model {modelName} saving failed', ['modelName' => 'Message']));
             }
         }
         if (!$model->save()) {
             throw new ErrorException(Yii::t('app', 'Model {SourceMessage} saving failed', ['modelName' => 'Message']));
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'relatedModels' => $relatedModels]);
     }
 }