CActiveDataProvider with parametrized scope bug

I have this code

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

if ($dataProvider->totalItemCount) {


       'dataProvider'  => $dataProvider,

       'city'          => $city,

       'category'      => $category,



where childrenFor is defined as

public function childrenFor($id)



          '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?