I use Yii version 1 (Sorry for this job! )
I need to remove and ignore a compare or override it.
See this code:
$criteria = new CDbCriteria();
$criteria->compare('title', 'anything');
//...more criteria in here
$criteria->compare('userId', 100);
$models = Video::model()->findAll($criteria);
var_dump($models);
For above example, I need ignore userId
in compare or search for another user, If there is not model for it and search for all models with keep other things compare and join tables in criteria.
Be like this code:
$criteria = new CDbCriteria();
$criteria->compare('title', 'anything');
//...more criteria in here
$criteria->compare('userId', 100);
$models = Video::model()->findAll($criteria);
if (!$models) {
$criteria->ignoreCompare('userId'); //just ignore `userId` and keep other things criteria
$criteria->overrideCompare('userId', 200); //or just override `userId` and keep other things criteria
$models = Video::model()->findAll($criteria);
}
var_dump($models);
The ignoreCompare
and overrideCompare
itโs just imaginary methods! I donโt found any method be like these.
How can I do it?