CActiveDataProvider with parametrized scope bug

I have this code




$dataProvider = new CActiveDataProvider(Categories::model()->childrenFor($categoryId));

if ($dataProvider->totalItemCount) {

   $this->render('categories',array(

       'dataProvider'  => $dataProvider,

       'city'          => $city,

       'category'      => $category,

   ));

}



where childrenFor is defined as




public function childrenFor($id)

{

    $this->getDbCriteria()->mergeWith(array(

          'condition' => 't.parent_id = "' . $id . '"',

    ));

    return $this;

}



In the view




<?php foreach($dataProvider->getData() as $k => $cat): ?>

...

<?php endforeach;?>



$dataProvider in a view returns me all records from table without filtering them by scope, although $dataProvider->totalItemCount returns the right number.

What is wrong in my code?

Found the problem.

if instead of this




if ($dataProvider->totalItemCount)) {



I write this




if (!empty($dataProvider->data)) {



then everything works as it should be.

Is it a bug or a feature?