title: How does the update operation work in Yii
body: <p>I'm new to Yii framework. I created a table <code>TblUser</code>. Now, I have three columns <code>username</code>,<code>password</code> and <code>email</code>.
  I'm using <code>CRUD</code> operations in Yii. Connection to database is successfully made. I was able to create a new record in the table also.
  Now the entry in the database reads as  </p>
  
  <pre><code>+----+----------+----------+--------------------+
  | id | username | password | email              |
  +----+----------+----------+--------------------+
  |  1 | test1    | pass1    | test1@example.com  |
  |  2 | test2    | pass2    | test2@example.com  |
  |  3 | test3    | pass3    | test3@example.com  |
  +-----------------------------------------------+
  </code></pre>
  
  <p><strong>Now, in the view form I removed the field <code>email</code> by commenting (_form.php). I'm using this form to update the remaining fields.</strong></p>
  
  <pre><code> &lt;?php
      /* @var $this TblUserController */
      /* @var $model TblUser */
      /* @var $form CActiveForm */
      ?&gt;
  
      &lt;div class="form"&gt;
  
      &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
              'id'=&gt;'tbl-user-form',
              'enableAjaxValidation'=&gt;false,
      )); ?&gt;
  
              &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
              &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  
              &lt;div class="row"&gt;
                      &lt;?php echo $form-&gt;labelEx($model,'username'); ?&gt;
                      &lt;?php echo $form-&gt;textField($model,'username',array('size'=&gt;60,'maxlength'=&gt;128)); ?&gt;
                      &lt;?php echo $form-&gt;error($model,'username'); ?&gt;
              &lt;/div&gt;
  
              &lt;div class="row"&gt;
                      &lt;?php echo $form-&gt;labelEx($model,'password'); ?&gt;
                      &lt;?php echo $form-&gt;passwordField($model,'password',array('size'=&gt;60,'maxlength'=&gt;128)); ?&gt;
                      &lt;?php echo $form-&gt;error($model,'password'); ?&gt;
              &lt;/div&gt;
  &lt;!--    
              &lt;div class="row"&gt;
                      &lt;?php echo $form-&gt;labelEx($model,'email'); ?&gt;
                      &lt;?php echo $form-&gt;textField($model,'email',array('size'=&gt;60,'maxlength'=&gt;128)); ?&gt;
                      &lt;?php echo $form-&gt;error($model,'email'); ?&gt;
              &lt;/div&gt;
  --&gt;    
              &lt;div class="row buttons"&gt;
                      &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
              &lt;/div&gt;
  
      &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>
  
  <p>To use rest of the fields I commented the <code>email</code> field in the _form.php. 
  Now in my controller I have the update code as shown below :</p>
  
  <pre><code>public function actionUpdate($id)
          {
                  $model=$this-&gt;loadModel($id);
  
                  // Uncomment the following line if AJAX validation is needed
                  // $this-&gt;performAjaxValidation($model);
  
                  if(isset($_POST['TblUser']))
                  {
                          $model-&gt;attributes=$_POST['TblUser'];
                          if($model-&gt;save())
                                  $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
                  }
  
                  $this-&gt;render('update',array(
                          'model'=&gt;$model,
                  ));
          }
  </code></pre>
  
  <p>When I see my query logs, the query updated is </p>
  
  <pre><code>UPDATE `tbl_user` SET `id`=2, `username`='1234', `password`='1234', `email`='test2@example.com' WHERE `tbl_user`.`id`=2  
  </code></pre>
  
  <p>and not  </p>
  
  <pre><code>UPDATE `tbl_user` SET `password`='1234' WHERE `tbl_user`.`id`=2  
  </code></pre>
  
  <p><strong>Now my question why is updating the unchanged values again instead of updating only changed values.</strong> Does Yii do this update query for everything. How does this work.</p>