title: Yii 2 – Can't use Model Update
body: <p>I have some code:</p>
  
  <pre><code>public function actionEditpost($id) {
      $post = SiteBlogPosts::find()-&gt;
              where(["id" =&gt; $id])-&gt;
              asArray()-&gt;
              one();
  
      $model = new SiteBlogPosts();
      $model-&gt;id = $post['id'];
      $model-&gt;DateCreated = $post['DateCreated'];
      $model-&gt;Author = $post['Author'];
      $model-&gt;Title = $post['Title'];
      $model-&gt;PreviewText = $post['PreviewText'];
      $model-&gt;FullTextOfPost = $post['FullTextOfPost'];
      $model-&gt;CategoryID = $post['CategoryID'];
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
  
          if ($model-&gt;validate()) {
  
              $model-&gt;update();
              print_r($model);
              die;
              return $this-&gt;render('AddPostDone', ['model' =&gt; $model]);
          }
      } else {
          $cats = SiteBlogCats::find()-&gt;where(["CatIsActive" =&gt; 1])-&gt;asArray()-&gt;all();
          return $this-&gt;render('EditPost', ['cats' =&gt; $cats,
                      "model" =&gt; $model,
                      'oldPost' =&gt; $post,
          ]);
      }
  }
  </code></pre>
  
  <p>This code works incorrectly - it doesn't update record in MySQL.
  In <code>/runtime/debug</code> logs I found interesting moment:</p>
  
  <blockquote>
  <pre><code>"UPDATE `SiteBlogPosts` SET `id`=5, `DateCreated`='2015-06-11', `Author`=1,
    `Title`='We are improved build mode!',
    `PreviewText`='&lt;div class=\"post-content\"&gt;\r\n&lt;p&gt;Hi.&lt;/p&gt;\r\n\r\n&lt;p&gt;&lt;/p&gt;\r\n\r\n&lt;p&gt;We are improved build mode! Also, we added simple Mirror Material Test.&lt;/p&gt;\r\n\r\n&lt;p&gt;&lt;iframe height=\"350\" src=\"http://www.youtube.com/embed/FLQ4i_av7HM\" width=\"425\"&gt;&lt;/iframe&gt;&lt;/p&gt;\r\n&lt;/div&gt;\r\n',
    `FullTextOfPost`='&lt;div class=\"post-content\"&gt;\r\n&lt;p&gt;Hi.&lt;/p&gt;\r\n\r\n&lt;p&gt;&lt;/p&gt;\r\n\r\n&lt;p&gt;We are improved build mode! Also, we added simple Mirror Material Test.&lt;/p&gt;\r\n\r\n&lt;p&gt;&lt;iframe height=\"350\" src=\"http://www.youtube.com/embed/FLQ4i_av7HM\" width=\"425\"&gt;&lt;/iframe&gt;&lt;/p&gt;\r\n&lt;/div&gt;\r\n',
    `CategoryID`=1 
  WHERE `id` IS NULL"
  </code></pre>
  </blockquote>
  
  <p>Otherwise, <code>print_r</code> shows:</p>
  
  <pre><code>app\models\SiteBlogPosts Object
  (
      [sqlCreateQuery] =&gt; 
      [_attributes:yii\db\BaseActiveRecord:private] =&gt; Array
          (
              [id] =&gt; 5
              [DateCreated] =&gt; 2015-06-11
              [Author] =&gt; 1
              [Title] =&gt; We are improved build mode!
              [PreviewText] =&gt; &lt;div class="post-content"&gt;
  &lt;p&gt;Hi.&lt;/p&gt;
  
  &lt;p&gt;&lt;/p&gt;
  
  &lt;p&gt;We are improved build mode! Also, we added simple Mirror Material Test.&lt;/p&gt;
  
  &lt;p&gt;&lt;iframe height="350" src="http://www.youtube.com/embed/FLQ4i_av7HM" width="425"&gt;&lt;/iframe&gt;&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Why it used <code>WHERE id IS NULL</code> instead of <code>WHERE id = 5</code>?</p>
  
  <p>Thank you!</p>