title: CGridView with relations, ID filter doesn't work `Integrity constraint violation`
body: <p>I'm trying to make a cgridview that can filter data from relations table. This is my first time with CGridView and I just can't get it to work. Help is appreciated.
  I have 2 problems. first: i have managed to get a dropdown filter of my users (avtor, relation in Novica), but when I choose one, it always returns this: "No results found.".
  second: When I try to filter with Novica.ID, i get this error: (filtering with other columsn works great)</p>
  
  <blockquote>
    <p>Error 500: <h1>CDbException</h1> <p>CDbCommand failed to execute the
    SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052
    Column 'id' in where clause is ambiguous. The SQL statement executed
    was: SELECT COUNT(*) FROM <code>novica</code> <code>t</code>  LEFT OUTER JOIN <code>uporabnik</code>
    <code>avtor</code> ON (<code>t</code>.<code>uporabnik_id</code>=<code>avtor</code>.<code>id</code>)  WHERE ((uporabnik_id =
    :id) AND (id=:ycp0))
    (C:\xampp\htdocs\PEF\framework\db\CDbCommand.php:528)</p><pre>0
  C:\xampp\htdocs\PEF\framework\db\CDbCommand.php(425):
  CDbCommand->queryInternal('fetchColumn', 0, Array) 1
  C:\xampp\htdocs\PEF\framework\db\ar\CActiveFinder.php(762):
  CDbCommand->queryScalar() 2
  C:\xampp\htdocs\PEF\framework\db\ar\CActiveFinder.php(155):
  CJoinElement->count(Object(CDbCriteria)) 3
  C:\xampp\htdocs\PEF\framework\db\ar\CActiveRecord.php(1540):
  CActiveFinder->count(Object(CDbCriteria)) 4
  C:\xampp\htdocs\PEF\framework\web\CActiveDataProvider.php(179):
  CActiveRecord->count(Object(CDbCriteria)) 5
  C:\xampp\htdocs\PEF\framework\web\CDataProvider.php(193):
  CActiveDataProvider->calculateTotalItemCount() 6
  C:\xampp\htdocs\PEF\framework\web\CActiveDataProvider.php(129):
  CDataProvider->getTotalItemCount() 7
  C:\xampp\htdocs\PEF\framework\web\CDataProvider.php(137):
  CActiveDataProvider->fetchData() 8
  C:\xampp\htdocs\PEF\framework\zii\widgets\CBaseListView.php(105):
  CDataProvider->getData() 9
  C:\xampp\htdocs\PEF\framework\zii\widgets\grid\CGridView.php(269):
  CBaseListView->init() 10
  C:\xampp\htdocs\PEF\framework\web\CBaseController.php(148):
  CGridView->init() 11
  C:\xampp\htdocs\PEF\framework\web\CBaseController.php(173):
  CBaseController->createWidget('zii.widgets.gri...', Array) 12
  C:\xampp\htdocs\PEF\protected\views\adminNovica\index.php(28):
  CBaseController->widget('zii.widgets.gri...', Array) 13
  C:\xampp\htdocs\PEF\framework\web\CBaseController.php(127):
  require('C:\xampp\htdocs...') 14
  C:\xampp\htdocs\PEF\framework\web\CBaseController.php(96):
  CBaseController->renderInternal('C:\xampp\htdocs...', Array, true) 15
  C:\xampp\htdocs\PEF\framework\web\CController.php(870):
  CBaseController->renderFile('C:\xampp\htdocs...', Array, true) 16
  C:\xampp\htdocs\PEF\protected\controllers\AdminNovicaController.php(19):
  CController->renderPartial('index', Array) 17
  C:\xampp\htdocs\PEF\framework\web\actions\CInlineAction.php(50):
  AdminNovicaController->actionIndex() 18
  C:\xampp\htdocs\PEF\framework\web\CController.php(309):
  CInlineAction->runWithParams(Array) 19
  C:\xampp\htdocs\PEF\framework\web\CController.php(287):
  CController->runAction(Object(CInlineAction)) 20
  C:\xampp\htdocs\PEF\framework\web\CController.php(266):
  CController->runActionWithFilters(Object(CInlineAction), Array) 21
  C:\xampp\htdocs\PEF\framework\web\CWebApplication.php(276):
  CController->run('') 22
  C:\xampp\htdocs\PEF\framework\web\CWebApplication.php(135):
  CWebApplication->runController('adminnovica') 23
  C:\xampp\htdocs\PEF\framework\base\CApplication.php(162):
  CWebApplication->processRequest() 24
  C:\xampp\htdocs\PEF\index.php(13): CApplication->run() 25 {main}</pre></p>
  </blockquote>
  
  <p>These are my tables:</p>
  
  <p><img src="https://i.stack.imgur.com/Hhm0A.png" alt="er"></p>
  
  <p>Models:
  Novica (eng: News)</p>
  
  <pre><code>public function relations() {
          return array(
              'uporabnik' =&gt; array(self::BELONGS_TO, 'DostopNovica', 'uporabnik_id'),
              'avtor' =&gt; array(self::BELONGS_TO, 'Uporabnik', 'uporabnik_id'),
          );
      }
  
  public function search() {
          $criteria = new CDbCriteria;
          $criteria-&gt;compare('id', $this-&gt;id);
          $criteria-&gt;with = 'avtor';
          $criteria-&gt;compare('naslov', $this-&gt;naslov, true);
          $criteria-&gt;compare('datum', $this-&gt;datum, true);
          $criteria-&gt;compare('avtor.upime', $this-&gt;uporabnik_id, true); //avtor.upime (eng. author.username)
  
      return new CActiveDataProvider(get_class($this), array(
                  'criteria' =&gt; $criteria,
                  'sort' =&gt; array(
                      'defaultOrder' =&gt; 'datum DESC', //date
                  ),
                  'pagination' =&gt; array(
                      'pageSize' =&gt; 5
                  ),
              ));
  }
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code> public function actionIndex() {
              $model = new Novica('search');
              if (isset($_GET['Novica']))
                  $model-&gt;attributes = $_GET['Novica'];
  
              $params = array(
                  'model' =&gt; $model,
              );
  
              if (!isset($_GET['ajax']))
                  $this-&gt;render('index', $params);
              else
                  $this-&gt;renderPartial('index', $params);
          }
  </code></pre>
  
  <p>CGridView:</p>
  
  <pre><code>$this-&gt;widget('zii.widgets.grid.CGridView', array(
      'dataProvider' =&gt; $model-&gt;search(),
      'filter' =&gt; $model,
      'columns' =&gt; array('id',
          array('name' =&gt; 'datum',
              'value' =&gt; 'date("j.n.Y G:i", strtotime($data-&gt;datum))'
          ),
          array(
              'name' =&gt; 'uporabnik_id',
              'value' =&gt; 'Uporabnik::Model()-&gt;FindByPk($data-&gt;uporabnik_id)-&gt;upime',
              'filter' =&gt; CHtml::listData(Uporabnik::model()-&gt;findAll(), 'id', 'upime'),
          ),
          'naslov'
      //specify the colums you wanted here
      ),
  ));
  </code></pre>