Cactivedataprovider Column Not Found

Hi,

I’m a bit confused about the different behaviour between ::model() and CActiveDataProvider. Using the same criteria object:


$crit = new CDbCriteria();

$crit->with = array( 'categoryHasLanguages' );

$crit->select = array(

	'id',

	new CDbExpression('IFNULL(categoryHasLanguages.translation, t.name) AS name'),

	'slug'

);

$crit->addColumnCondition( array(

	'id_organization' => $organization,

	'categoryHasLanguages.id_language' => $lang,

) );

Calling


Category::model()->findAll( $crit );

works, but calling


$dataProvider = new CActiveDataProvider( 'Category', array( 'criteria' => $crit, ) );

, doesn’t. I know how to get it working, adding


$crit->together = true;

, but I’m asking if someone can explain this to me :)

Hi kwyjibo, welcome to the forum.

I just wrote a wiki on this issue. Please take a look at this.

http://www.yiiframework.com/wiki/527/relational-query-lazy-loading-and-eager-loading-with-and-together/

In addition, please note that usually ‘LIMIT’ is added implicitly to the criteria when you are working with CActiveDataProvider.

Wow, very clear explanation ;) Thank you!