How to compare an attribute with a function in CDbCriteria ?

I have a function in my model

public function getLastContact()


	return !empty($this->contacts)?$this->contacts[0]->contact_time:'';


Is there a way to search the above function with the attribute from gridview search?

Something similar to below

public function search()


	$criteria=new CDbCriteria;






	return new CActiveDataProvider($this, array(




Unfortunately this won’t work.

As you see in the reference, the first parameter for CDbCriteria::compare() is


Usually it is a name of a column in a table. You can not use a PHP method here.

But you can use a valid SQL expression instead of a column name here. So what you have to do is write some SQL expression that is equivalent to the PHP method "getLastContact()".

Thank you for your support