title: Update field in the other table when using form create yii2 is something wrong
body: <p>I have three tables, you can see in this picture bellow. And then I've created form skpaa and the data values in form will save to table skpaa and update one the field in the other table. I have the problem to form <strong>SKPAA</strong>, when user save to table skpaa I want the data value in table <strong>anak_asuh</strong> is like <strong>status</strong> changed based on <strong>kode anak asuh</strong> in form <strong>SKPAA</strong>. I've implemented with the following refrences use method <a href="http://www.yiiframework.com/doc-2.0/guide-db-dao.html#non-select-queries" rel="nofollow noreferrer">Executing Non-SELECT Queries</a> from doc yii2. But the result is strange when I save, the all data values in field <strong>status</strong> is changed.  <strong>I want the data value in field status changed based on form SKPAA</strong>. Please tell me how to solutions.. Thanks</p>
  
  <p>Controller: </p>
  
  <pre><code>public function actionCreate()
  {
      // Skpaa
      $skpaa = new Skpaa();
      if (!$skpaa) {
          throw new NotFoundHttpException("The skpaa was not found.");
      }
  
      // Display datetime in form and save to table
      $skpaa-&gt;tgl_skpaa = date('Y-m-d');
  
      // Dispaly kode pengurus in form and save to table
      $skpaa-&gt;kode_pengurus = \Yii::$app-&gt;user-&gt;identity-&gt;kode_pengurus;  
  
      // Ska
      $ska = new Ska(); 
      if (!$ska) {
          throw new NotFoundHttpException("The ska was not found.");
      }
  
      // Calon Keluarga Asuh
      $calonKeluarga = new CalonKeluargaAsuh(); 
      if (!$calonKeluarga) {
          throw new NotFoundHttpException("The calon keluarga asuh was not found.");
      }
  
      // Anak asuh
      $anak_asuh = new AnakAsuh();
      if (!$anak_asuh) {
          throw new NotFoundHttpException("The anak asuh was not found.");
      }
  
      $anak_asuh-&gt;kode_anak_asuh = Yii::$app-&gt;db-&gt;createCommand()-&gt;update('anak_asuh', ['status' =&gt; 'Tetap'])-&gt;execute();
  
      // Calon anak
      $calon = new Calon(); 
      if (!$calon) {
          throw new NotFoundHttpException("The Calon was not found.");
      }
  
      // Calon anak
      $pengurus = new Pengurus(); 
      if (!$pengurus) {
          throw new NotFoundHttpException("The Pengurus was not found.");
      }
  
      if ($skpaa-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $anak_asuh-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $skpaa-&gt;save()) {
              Yii::$app-&gt;session-&gt;setFlash('success', 'Data berhasil disimpan!');
              return $this-&gt;redirect(['index']);
              return $this-&gt;refresh();
      }
  
      return $this-&gt;render('create', [
          'skpaa' =&gt; $skpaa,
          'ska' =&gt; $ska,
          'calonKeluarga' =&gt; $calonKeluarga,
          'anak_asuh' =&gt; $anak_asuh,
          'calon' =&gt; $calon,
          'pengurus' =&gt; $pengurus,
      ]);
  }
  </code></pre>
  
  <p>View :</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\bootstrap\ActiveForm;
  use yii\widget\Pjax;
  use yii\helpers\Url;
  use yii\db\ActiveRecord;
  use yii\helpers\ArrayHelper;
  use kartik\widgets\Select2;
  use yii\web\JsExpression;
  use app\models\Skpaa;
  use app\models\Ska;
  use app\models\CalonKeluargaAsuh;
  use app\models\AnakAsuh;
  use app\models\Calon;
  use app\models\User;
  use app\models\Pengurus;
  use kartik\widgets\DatePicker;
  
  $this-&gt;title = 'Surat Keterangan Penyerahan Anak Asuh';
  
  ?&gt;
  
  &lt;h1 align="center"&gt;Surat Keterangan Penyerahan Anak Asuh&lt;/h1&gt;
  &lt;?php
  echo "&amp;nbsp";
  echo "&amp;nbsp";
  ?&gt;
  
  &lt;?php $form = ActiveForm::begin([
      'layout' =&gt; 'horizontal', 
      'fieldConfig' =&gt; [
          'template' =&gt; "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
              'horizontalCssClasses' =&gt; [
              'label' =&gt; 'col-sm-4',
              'offset' =&gt; 'col-sm-offset-4',
              'wrapper' =&gt; 'col-sm-8',
              'error' =&gt; '',
              'hint' =&gt; '',
              'button' =&gt; 'col-sm-4'
          ],
      ],
      ]); 
  ?&gt;
  
  &lt;div class="panel panel-default"&gt; 
  
  &lt;div class="panel-heading"&gt;&lt;b&gt;&lt;h4 align="center"&gt;Form Tanda Terima&lt;/h4&gt;&lt;/b&gt;&lt;/div&gt;
  
  &lt;?php if (Yii::$app-&gt;session-&gt;hasFlash('success')): ?&gt;
    &lt;div class="alert alert-success alert-dismissable"&gt;
    &lt;button aria-hidden="true" data-dismiss="alert" class="close" type="button"&gt;×&lt;/button&gt;
    &lt;h4&gt;&lt;i class="icon fa fa-check"&gt;&lt;/i&gt;Informasi!&lt;/h4&gt;
    &lt;?= Yii::$app-&gt;session-&gt;getFlash('success') ?&gt;
  &lt;/div&gt;
  &lt;?php endif; ?&gt;
  
  &lt;div class="panel-body"&gt;  
  
  &lt;table class="table table-striped"&gt; 
  
  &lt;?php echo $form-&gt;field($skpaa, 'no_skpaa')-&gt;textInput(['style'=&gt;'width:350px', 'readOnly' =&gt; true]);
  ?&gt;
  
  &lt;?= $form-&gt;field($skpaa, 'tgl_skpaa')-&gt;widget(DatePicker::classname(), [
      'options' =&gt; [
          'id' =&gt; 'tgl_skpaa',
          'style' =&gt; 'width:350px',
          'disabled' =&gt; true
      ],
      'type' =&gt; DatePicker::TYPE_INPUT,
      'language' =&gt; 'id',
      'pluginOptions' =&gt; [
          'autoclose'=&gt;true,
          'format' =&gt; 'yyyy-mm-dd',
          ]
      ]); 
  ?&gt;
  
  &lt;?php
      $dataSka = ArrayHelper::map(Ska::find()-&gt;all(), 'no_ska', 'no_ska');
  ?&gt;
  &lt;?php 
      echo $form-&gt;field($skpaa, 'no_ska')-&gt;widget(Select2::classname(), [
      'data' =&gt; $dataSka,
      'language' =&gt; 'id',
      'options' =&gt; [
          'placeholder' =&gt; 'Pilih',
          'id' =&gt; 'no_ska',
      ],
      'pluginOptions' =&gt; [
          'allowClear' =&gt; true,
          'width' =&gt; '350px',
          ],
      ])-&gt;label('Nomor Surat Ketersediaan'); 
  ?&gt;
  
  &lt;?php 
      echo $form-&gt;field($calon, 'nama_calon')-&gt;textInput(['style'=&gt;'width:350px', 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php 
      echo $form-&gt;field($anak_asuh, 'kode_anak_asuh')-&gt;textInput(['style'=&gt;'width:350px']);
  ?&gt;
  
  &lt;?php 
      echo $form-&gt;field($calonKeluarga, 'nama')-&gt;textInput(['style'=&gt;'width:350px', 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php 
      echo $form-&gt;field($calonKeluarga, 'jenis_kelamin')-&gt;textInput(['style'=&gt;'width:350px', 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php 
      echo $form-&gt;field($calonKeluarga, 'alamat')-&gt;textInput(['style'=&gt;'width:350px', 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php 
      echo $form-&gt;field($calonKeluarga, 'pekerjaan')-&gt;textInput(['style'=&gt;'width:350px', 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php $kode_pengurus = \Yii::$app-&gt;user-&gt;identity-&gt;kode_pengurus ?&gt;
  &lt;?php 
      echo $form-&gt;field($skpaa, 'kode_pengurus')-&gt;textInput(['style'=&gt;'width:350px', 'value' =&gt; $kode_pengurus, 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php $nama_pengurus = \Yii::$app-&gt;user-&gt;identity-&gt;nama_pengurus ?&gt;
  &lt;?php 
      echo $form-&gt;field($pengurus, 'nama_pengurus')-&gt;textInput(['style'=&gt;'width:350px', 'value' =&gt; $nama_pengurus, 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php $alamat = \Yii::$app-&gt;user-&gt;identity-&gt;alamat ?&gt;
  &lt;?php 
      echo $form-&gt;field($pengurus, 'alamat')-&gt;textInput(['style'=&gt;'width:350px', 'value' =&gt; $alamat, 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php $pekerjaan = \Yii::$app-&gt;user-&gt;identity-&gt;pekerjaan ?&gt;
  &lt;?php 
      echo $form-&gt;field($pengurus, 'pekerjaan')-&gt;textInput(['style'=&gt;'width:350px', 'value' =&gt; $pekerjaan, 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;?php $jenis_kelamin = \Yii::$app-&gt;user-&gt;identity-&gt;jenis_kelamin ?&gt;
  &lt;?php 
      echo $form-&gt;field($pengurus, 'jenis_kelamin')-&gt;textInput(['style'=&gt;'width:350px', 'value' =&gt; $jenis_kelamin, 'disabled' =&gt; true]);
  ?&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="col-sm-offset-4"&gt;
  &lt;?= Html::submitButton('Simpan', ['class' =&gt; 'btn btn-primary']) ?&gt;
  &lt;?php
  echo "&amp;nbsp";
  echo "&amp;nbsp";
  echo Html::a('Keluar', ['/'], ['class' =&gt; 'btn btn-success']);
  ?&gt; 
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/table&gt;
  
  &lt;/div&gt;
  
  &lt;/div&gt; &lt;!-- /panel --&gt;
  
  &lt;/div&gt; &lt;!-- /container --&gt;
  
  &lt;?php ActiveForm::end();?&gt;
  </code></pre>
  
  <p>Model: </p>
  
  <pre><code>&lt;?php
  
  namespace app\models;
  
  use Yii;
  use yii\db\ActiveRecord;
  use app\models\Skpaa;
  use app\models\Pengurus;
  use app\models\User;
  use app\models\Ska;
  
  class Skpaa extends ActiveRecord 
  {
      public static function tableName()
      {
          return '{{%skpaa}}';
      }
  
      public function rules()
      {
          return [
              [['no_ska', 'kode_pengurus'], 'required'],
              [['tgl_skpaa'], 'safe'],
          ];
      }
  
      public function actributeLabels()
      {
          return [
              [
                  'no_skpaa' =&gt; 'Nomor Surat',
                  'tgl_skpaa' =&gt; 'Tanggal Surat',
                  'kode_pengurus' =&gt; 'Kode Pengurus',
                  'no_ska' =&gt; 'Nomor Surat Ketersediaan',    
              ],
          ];
      }
  
      // Autonumber for no_skpaa
      public function behaviors()
      {
      return [
          [
              'class' =&gt; 'mdm\autonumber\Behavior',
              'attribute' =&gt; 'no_skpaa', // required
              //'group' =&gt; $this-&gt;id_branch, // optional
              'value' =&gt; 'SKPAA'.'?' , // format auto number. '?' will be replaced with generated number
              'digit' =&gt; 2 // optional, default to null. 
          ],
  
         ];
      }
  
      public function getPengurus()
      {
          return $this-&gt;hasOne(Pengurus::className(), ['kode_pengurus' =&gt; 'no_skpaa']);
      }
  
      public function getSka()
      {
          return $this-&gt;hasOne(Ska::className(), ['no_ska' =&gt; 'no_skpaa']);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WUvQi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WUvQi.png" alt="My tables"></a></p>