$criteria->compare a different table than the model

In the CGrid I’m using, there is a column that can be searched that relates to data in a different table. For example:

        public function search()


		$criteria=new CDbCriteria;




		return new CActiveDataProvider(get_class($this), array(




This function resides in the Item model, referencing the item table. You can see where I try to reference a different table (itemcategory), but when this runs it just checks the Item table for the itemcategory.name column. The itemcategory relation is properly setup.

Any ideas?

Use criteria->with(array(‘itemcategory’));

before you use ‘compare’. :)

I get the error: CDbCriteria does not have a method named "with".

Use this syntax

$criteria->with = array('itemcategory');


That did the trick, thanks!