Cactivedataprovider Does Not Fetch All Records

Hi guys!

I use CGridView to display the goods from the shop. I tried to append a filter for them to display only goods with images. For that I have two models: Good and File. So my search method from Good model:

public function search()


	$criteria=new CDbCriteria;





    if ( $_GET['photo_exists'] ) {

        $criteria->with = array('files' => array(

            'condition' => ' IS NOT NULL',

            'together' => true,



	return new CActiveDataProvider($this, array(



			'pageSize'=> 40,




The result MySQL query from profiler ( SELECT section replaced by asterisk ):


FROM `good` `good` 

LEFT OUTER JOIN `file` `file` ON (`file`.`oid`=`good`.`id`) AND (file.type = "GOOD") 


ORDER BY DESC, file.pos 


The strange thing is displaying only 25 rows on the first page by CGridView, 16 on the second, and randomly further… The fact is I have about 250 records in database ( with the query I posted, if i run it - it returns exactly 40 rows ), but after the search method there are only about one hunded in summary from all pages.

Would you point me where I might be mistaken. Thank you.

i think you can add the limit on search function because after search you can call the this query

if ( $_GET['photo_exists'] ) {

        $criteria->with = array('files' => array(

            'condition' => ' IS NOT NULL',

            'together' => true,



so you can pass the limit on this query…

 'limit' = 40;

i hope it may be helpful…

Doesn’t work :( The thing is the limitation has been applied to SQL query as you might see from the query I posted, but something happened with the rest of the rows after the query.

I found out if I set pagination to false all the records displayed on one page all right, but how can I implement the pagination in this case ? :mellow:

Solved. The problem is some goods have multiple photos attached to them, it is One-to-Many relation. So even if I set

$criteria->distinct = true

the result the same 24 DISTINCT rows instead of 40. And duplicates has been filtered in CActiveFinder.populateRecord private method.

I just added grouping by and problem has been disappeared:

$criteria->group = '';

cool… :rolleyes: