title: Yii CGridView with HAS_MANY relation
body: <p>I am having quiet a bit of problem displaying HAS MANY relation within a CGridView. </p>
  
  <p>I want to display all the post titles for a particular author in CGridView seperated by a ',' (comma).</p>
  
  <p>Here's a simple example:</p>
  
  <p>I have the following tables:</p>
  
  <p><strong>author:id,name</strong></p>
  
  <p><strong>post:id,title,created(DATETIME),a_id.</strong></p>
  
  <p>Post belongs to Author through a_id.</p>
  
  <p>Model:</p>
  
  <pre><code>    public $postTitles;
  
      public function relations()
      {
              // NOTE: you may need to adjust the relation name and the related
              // class name for the relations automatically generated below.
              return array(
                      'posts' =&gt; array(self::HAS_MANY, 'Post', 'a_id'),
              );
      }
  
      public function search()
      {
              // @todo Please modify the following code to remove attributes that should   not be searched.
  
              $criteria=new CDbCriteria;
  
              $criteria-&gt;select="t.*,title AS postTitles";
              $criteria-&gt;join="LEFT OUTER JOIN post on a_id=t.id";
  
              $criteria-&gt;compare('id',$this-&gt;id);
              $criteria-&gt;compare('name',$this-&gt;name,true);
  
              return new CActiveDataProvider($this, array(
                      'criteria'=&gt;$criteria,
                      'sort'=&gt;array("attributes"=&gt;array(
                              'id',
                              'name',
                                 )),
              ));
      }
  
      public function getPostTitles() {
              $return = ',';
              foreach ($this-&gt;posts as $post) {
                      $return .= $post-&gt;title;
              }
              return $return;
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    public function actionIndex()
      {
              $model = new Author('search');
              $this-&gt;render('index', array('model' =&gt; $model));
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>    $this-&gt;widget('zii.widgets.grid.CGridView', array(
          'id'=&gt;'author-grid',
          'dataProvider'=&gt;$model-&gt;search(),
          'filter'=&gt;$model,
          'columns'=&gt;array(
              'id',
              'name',
              array(
                      'id'=&gt;'postTitles',
                      'type'=&gt;'raw',
                      'value'=&gt; array($model, 'getPostTitles'), 
              ),
  
              array(
                      'class'=&gt;'CButtonColumn',
              ),
          ),
      )); 
  </code></pre>