title: Yii - Saving data back to Many-to-Many Relation database, from a dropdownlist with multiple-selection
body: <p>(Please pardon my poor English.)
  I am having 3 tables, say <strong>Blog</strong>, <strong>User</strong> and <strong>user_blog</strong>.</p>
  
  <p><strong>Blog</strong></p>
  
  <pre><code>CREATE TABLE `Blog` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(64) NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p><strong>User</strong></p>
  
  <pre><code>CREATE TABLE `User` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(256) NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p><strong>user_blog</strong></p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `user_blog` (
    `user_id` int(11) NOT NULL,
    `blog_id` int(11) NOT NULL,
    PRIMARY KEY (`user_id`,`blog_id`)
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p>and i have declared their relations in the respective AR models.</p>
  
  <p><strong>Blog.php</strong></p>
  
  <pre><code>public function relations() {
     return array(
        'users' =&gt; array(self::MANY_MANY, 'User', 'user_blog(blog_id, user_id)'),
     );
  }
  </code></pre>
  
  <p><strong>User.php</strong></p>
  
  <pre><code>public function relations() {
     return array(
        'blogs' =&gt; array(self::MANY_MANY, 'Blog', 'user_blog(user_id, blog_id)'),
     );
  }
  </code></pre>
  
  <p>And now, I have in my view the following codes:</p>
  
  <pre><code>&lt;?php
     $data = CHtml::listData(User::model()-&gt;findAll(), "id", "name");
     echo $form-&gt;dropDownList($blog,'users', $data, array('multiple'=&gt;'multiple', 'size' =&gt; '5'));
  ?&gt;
  </code></pre>
  
  <p>With the above code, a dropdownlist with multiple selection is successfully created, and the data from the database are successfully retrieved and the items that are supposed to be selected are successfully highlighted.</p>
  
  <p>But here comes the problem. I have no idea how to implement the saving/updating function. No matter what options I have selected, the results are not saved back to the database.</p>
  
  <p>Could anyone please help?
  Thank you in advance.</p>