title: Yii composite primary keys with isNewRecord
body: <p>I have a mysql table with composite keys ( user_id , category_id );
  I am trying to update the last access for these records as following</p>
  
  <pre><code>$userCategory = new UserCategory;
  $userCategory-&gt;user_id = 1;
  $userCategory-&gt;category_id = 15;
  echo $userCategory-&gt;isNewRecord; //always true
  $userCategory-&gt;last_access = Now();
  
  $userCategory-&gt;save();
  </code></pre>
  
  <p>The {$userCategory->isNewRecord} and when I try to save() the MySQL generates a duplicate error for the composite Primary keys.</p>
  
  <p>I also added this to UserCategory model but didn't help</p>
  
  <pre><code>public function primaryKey() {
          return array('user_id', 'category_id');
      }
  </code></pre>
  
  <p>****Update:
  Sorry for the confusion. My question is how to achieve the same result as "ON DUPLICATE KEY UPDATE" in the Yii framework. In other words, how to do the insert or update in one SQL query. if you look at the source code for <a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecord#save-detail" rel="noreferrer">save()</a></p>
  
  <pre><code>public function save($runValidation=true,$attributes=null)
  {
      if(!$runValidation || $this-&gt;validate($attributes))
          //checking if new record
          return $this-&gt;getIsNewRecord() ? $this-&gt;insert($attributes) : $this-&gt;update($attributes);**
      else
          return false;
  }
  </code></pre>