title: yii2 querying with custom column gives : Unknown column 'columnname' in 'having clause'
body: <p>i am caught up in a situation here</p>
  
  <p>i have a small custom search model's code here</p>
  
  <pre><code>    $query = Ad::find();
  
      $dataProvider = new ActiveDataProvider([
          'query' =&gt; $query,
      ]);
  
      if($subcategorymodel){
          $query-&gt;andFilterWhere([
              'sub_category_id' =&gt; $subcategorymodel-&gt;id,
          ]);
      }
      if($adcategorymodel){
          $query-&gt;andFilterWhere([
              'ad_category_id' =&gt; $adcategorymodel-&gt;id,
          ]);
      }
      if($nearmodel){
          $lat = $nearmodel-&gt;latitude;
          $long = $nearmodel-&gt;longitude;
          $query-&gt;select('*, (
          (
          ACOS( SIN( '.$lat.' * PI( ) /180 ) * SIN( latitude * PI( ) /180 ) + COS( '.$lat.' * PI( ) /180 ) * COS( latitude * PI( ) /180 ) * COS( ( '.$long.' - `longitude` ) * PI( ) /180 ) ) *180 / PI( )
          ) *60 * 1.1515 * 1.609344
          ) AS distance');
  
          $query-&gt;having('distance &lt;=100'); //condition for my custom column
      }
  
      $query-&gt;andFilterWhere([
          'status' =&gt; 1,
      ]);
  
      return $dataProvider;
  </code></pre>
  
  <p>which runs fine with the $query->having('distance &lt;=100'); clause but i get this error</p>
  
  <pre><code>   SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause'
     The SQL being executed was: SELECT COUNT(*) FROM `tbl_ad` WHERE ((`sub_category_id`=1) AND    (`ad_category_id`=1)) AND (`status`=1) HAVING distance &lt;=100
     Error Info: Array
     (
       [0] =&gt; 42S22
       [1] =&gt; 1054
       [2] =&gt; Unknown column 'distance' in 'having clause'
  </code></pre>
  
  <p>at the view what i have is</p>
  
  <pre><code>&lt;?php 
      echo ListView::widget([
       'dataProvider' =&gt; $dataProvider,
       'itemOptions' =&gt; ['class' =&gt; 'item'],
       'itemView' =&gt; '_item_view',
       'pager' =&gt; ['class' =&gt; \kop\y2sp\ScrollPager::className()]
  ]);
  ?&gt;
  </code></pre>
  
  <p>and on inspection of the error stack, somewhere around the codes, yii2 calls this function here (i guess to play with the pagination data)</p>
  
  <pre><code>public function count($q = '*', $db = null)
  {
      return $this-&gt;queryScalar("COUNT($q)", $db);
  }
  </code></pre>
  
  <p>so, is there a solution/work-around for this?</p>