The addSearchCondition function does not add search condition in the right order, check my code:
$criteria = new CDbCriteria();
$criteria->order = 'id ASC';
$criteria->limit = $limit;
$criteria->offset = $offset;
if( ! empty($typeID) ) {
$criteria->addICondition('type_id', array($typeID)) ;
}
if( ! empty($userID) ) {
$criteria->addInCondition('user_id', array($userID)) ;
}
if( ! empty($key) ) {
$criteria->addSearchCondition('tags', $key , true , 'OR');
$criteria->addSearchCondition('title', $key , true , 'OR');
$criteria->addSearchCondition('description', $key , true , 'OR');
}
if( ! empty($categories) ) {
$criteria->addInCondition('category_id', $categories) ;
}
print_r($criteria);
The condition parameters contains the following:
((((type_id=:ycp0) AND (user_id=:ycp1)) OR (tags LIKE :ycp2)) OR (title LIKE :ycp3)) OR (description LIKE :ycp4)
which is wrong!
It should be something like this
(type_id=:ycp0) AND (user_id=:ycp1) AND (tags LIKE :ycp2) OR (title LIKE :ycp3) OR (description LIKE :ycp4)
I can’t find any solution but to do it manually!
Any suggestions?