CDbCriteria->mergeWith() is replacing instead of merging

$dbCriteria = new CDbCriteria;

foreach($model->fields as $id => $value) {

	if(!empty($value)) {

		$fieldCriteria = new CDbCriteria;


		$fieldCriteria->addSearchCondition('value', $value);

		$dbCriteria->mergeWith($fieldCriteria, false);	



I’m having trouble merging these criteria into a single query. Each of the FieldCriteria generates a condition like this:

sql AND (value LIKE :ycp1)[/sql]

I want each of these separated by an OR statement, kind of like this:

[sql]((field.field_id=:ycp0) AND (value LIKE :ycp1)) OR ((field.field_id=:ycp2) AND (value LIKE :ycp3)) OR ((field.field_id=:ycp4) AND (value LIKE :ycp5))[/sql]

However, $dbCriteria overwrites its own criteria with those of the last $fieldCriteria it was merged with, instead of merging with it. So after the above loop, it just takes on the criteria of the last generated $fieldCriteria. What’s going on?

After some more research I entered Issue 676 together with a possible fix.