CActiveDataProvider and Relations

I recently updated my code to use CActiveDataProvider with CListView. I am having a problem accessing relations though. Here is what I have:

Model relation:

'rel_genres'=>array(self::HAS_MANY, 'Option', 'link_id', 'condition'=>'gen.attribute_id=4', 'alias'=>'gen'),


$criteria=new CDbCriteria;




	array_push($criteria->with, 'rel_genres');

	$criteria->addInCondition('gen.value', $_GET['genre']);



$dataProvider=new CActiveDataProvider($model, array(







<?php $this->widget('zii.widgets.CListView', array(



)); ?>

This was all working fine before I changed to CActiveDataProvider (I was using a standard findAll() before that).

The error I am getting is: Column not found: 1054 Unknown column ‘gen.value’ in ‘where clause’

My first suggestion would be to specify the alias ‘gen’ in $criteria. IIRC, at least some of the criterias declared in the relationship only takes effect on lazy loading.


Nope, that has not helped either.

I did a search of the forum and found this:

It looks like the same issue - in which case it’s a problem with CActiveDataProvider.

Though I’m not too keep on using the solution posted in that topic, but would welcome any other suggestions…

This seems to have fixed the problem:


However I’m not sure why I didn’t need this when I was using findAll()!