Using "OR" in Relational Active Record

I’m implementing a search page in a social netwrking app, and I want to do a global search for whether a user or one of its related attributes contain the specified search term.

Basically, I want the combined result of the following RAR queries:




User::model()->with(array('field_values'=>array('condition'=>'value LIKE :term', 'params'=>array('term'=>'%'.$model->term.'%'))))->findAll();


User::model()->findAll(array('condition'=>'name LIKE :term', 'params'=>array('term'=>'%'.$model->term.'%')));



Is it possible to combine these two queries into one? Later on I need to search for even more properties and it seems a bit overkill to me to have to do each of these queries separately, when it could be achieved using a simple ‘OR’ operator in a native SQL query.

For the record, I solved this using CDbCriteria:




$dbCriteria = new CDbCriteria();

$dbCriteria->addSearchCondition('name', $model->term);

$dbCriteria->addSearchCondition('field_values.value', $model->term, true, 'OR');

$results = User::model()->with('field_values')->findAll($dbCriteria);



Eagerly loading the field_values table in this case is essential because otherwise there will be problems searching in its table columns (default is lazy loading, so it won’t be joined at all)