Yii Framework Forum: CDbCriteria->mergeWith() is replacing instead of merging - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CDbCriteria->mergeWith() is replacing instead of merging Rate Topic: -----

#1 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 11 November 2009 - 10:24 AM

$dbCriteria = new CDbCriteria;
foreach($model->fields as $id => $value) {
	if(!empty($value)) {
		$fieldCriteria = new CDbCriteria;
		$fieldCriteria->addColumnCondition(array('field.field_id'=>$id));
		$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:
(field.field_id=:ycp0) AND (value LIKE :ycp1)


I want each of these separated by an OR statement, kind of like this:
((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))


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?
0

#2 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 12 November 2009 - 06:43 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users