I solved the problem by using the following :
In my model : $productsList=products::model()->findAll($criteria);
In my view :
<?php foreach($productsList as $n=>$model):
$category = products::model()->findbyPk($model->categoryID); ?>
<tr class="<?php echo $n%2?'even':'odd';?>">
<td><?php echo CHtml::link($model->id,array('show','id'=>$model->id)); ?></td>
<td><?php echo CHtml::encode($model->name); ?></td>
<td><?php echo CHtml::encode($model->unit); ?></td>
<td><?php echo CHtml::encode($category->name); ?></td>
<td>
<?php echo CHtml::link('Update',array('update','id'=>$model->id)); ?>
<?php echo CHtml::linkButton('Delete',array(
'submit'=>'',
'params'=>array('command'=>'delete','id'=>$model->id),
'confirm'=>"Are you sure to delete #{$model->id}?")); ?>
</td>
</tr>
<?php endforeach; ?>
Now, I know this is not the right way but it was the only way it worked.
I found that when I was previously using the with('category')->findall() function and in my view using : $model->category->name - i was getting errors. I noted that $model->category was an array. If I dumped the $model->category-name object (using var_dump()) the category data that corresponded to each product was not up to date as in the database.
I have thought that maybe it is caching something ? Or maybe the lazy loading has something to do with my error ? As I am new to this framework, I am eager to understand as much as I can about it.
Any feedback is so welcome at the moment regarding this issue.
Thanks.