Yii criteria mergeWith problem

I am using criteria’s mergeWith() method, it is not working how it is supposed to work:

here is two criterias:

1:


[condition] => ( agegroupid=1) AND (methodid IN (:ycp0, :ycp1))

            [params] => Array

                (

                    [:ycp0] => 17

                    [:ycp1] => 18

                )

2:


[condition] => (methodid=:ycp0) AND (categoryid  =0)

            [params] => Array

                (

                    [:ycp0] => 9

                )

i am using $criteria1->mergeWith($criteria2, false);

what i am getting:


[condition] => (( agegroupid=1) AND (methodid IN (:ycp0, :ycp1))) OR ((methodid=:ycp0) AND (categoryid  =0))

    [params] => Array

        (

            [:ycp0] => 9

            [:ycp1] => 18

        )

they are merged with or: that is correct

but with params second one is overriding param of first one, i look inside merge function and found:


if($this->params!==$criteria->params)

		$this->params=array_merge($this->params,$criteria->params);

if it merges and in two different criteria’s conditions key will start from the same key(:ycp0) and the second ones param will overried first ones. How to fix that? or i am using it incorrect?

hi

you have to use criteria like below

$criteria = new CDbCriteria;

$criteria->addCondition(‘t.id = :id’);

$criteria->params = array(’:id’ => Yii::app()->user->id);

Model_name::model()->findAll($criteria);

Thanks

what about if i want this:




$criteria = new CDbCriteria;

$criteria->addCondition('t.id = :id');

$criteria->params = array(':id' => 1);


$criteria2 = new CDbCriteria;

$criteria2->addCondition('t.id = :id');

$criteria2->params = array(':id' => 2);


$criteria2->mergeWith($criteria1, false);


Model_name::model()->findAll($criteria2);



it is not possible?

I think that on a thread recently someone came with this tip:




$criteria = new CDbCriteria;

$criteria->addCondition('t.id = :id1');

$criteria->params = array(':id1' => 1);


$criteria2 = new CDbCriteria;

$criteria2->addCondition('t.id = :id2');

$criteria2->params = array(':id2' => 2);


$criteria2->mergeWith($criteria1, false);


Model_name::model()->findAll($criteria2);



Otherwise, the first value would be overwritten