Using CDbCriteria.with doesn't load but one record.

Hi, I have a criteria which involves a master table and two related tables, so I defined my relationships using self::BELONGS_TO. I define the $criteria->with() with the proper relations, and launch the findAll. The SQL looks fine and if I run it with, say phpMyAdmin, it returns every record (10,000+ records in this case), but findAll returns only the first one!!. But if I delete the $criteria->with, it returns every record, but it fires up 10,000+ queries to find the related data. I really don’t understand what could be wrong:

master (Log) model relations:


public function relations()

{

 	return array(

      	'users'=>array(self::BELONGS_TO, 'Users', 'uid'),

      	'profile'=>array(self::BELONGS_TO, 'Profile', 'uid'),

 	);

}


$criteria = new CdbCriteria();

$criteria->select = 'info';

$criteria->condition = 't.uid=:uid';

$criteria->params = array(':uid'=>$model->uid);

$criteria->addBetweenCondition('date', $model->start_date, $model->final_date);

$criteria->order = 'date ASC';

$criteria->with = array(

              	'profile'=>array(

                  	'select'=>'name',

              	),

              	'users'=>array(

                  	'select'=>'email,login',

              	),

   			);


$records = Log::model()->findAll($criteria); // this returns ONE record, but the SQL created by 

// Yii returns all 10,000 records if run directly in mysql.


$criteria = new CdbCriteria();

$criteria->select = 'info';

$criteria->condition = 't.uid=:uid';

$criteria->params = array(':uid'=>$model->uid);

$criteria->addBetweenCondition('date', $model->start_date, $model->final_date);

$criteria->order = 'date ASC';


$records  = Log::model()->findAll($criteria); // this returns all 10,000 records but executes 

// 10,000 queries when I loop through $records to get the information.

Any help is appreciated.

Oh, I found the problem. Since my table is a log of events, which can be huge, I didn’t define a PK (by design), but since Yii requires a PK to be defined, I used [font=“Courier New”]uid[/font] as the primaryKey in the model, and this causes the problem: since I’m looking for an specific uid, just one result will be included by Yii in the result set. This is kind of annoying. I really don’t want to define an auto_increment PK on that table. How can I overcome this limitation?

This is a similar problem