I
I
ImPuuLsE2015-04-24 11:25:31
Yii
ImPuuLsE, 2015-04-24 11:25:31

How to merge CDbCriteria in Yii 1?

Hello! Wanted to combine the conditions.

$criteriaCompare = new CDbCriteria();
            $criteriaCompare->with = array('manufacturer');
            $criteriaCompare->compare('manufacturer.archive' , 'n');

            $criteriaCondition = new CDbCriteria();
            $criteriaCondition->order = 'RAND()';
            $criteriaCondition->limit = self::SIDEBAR_LIDERS_COUNT;
            $criteriaCondition->addCondition("of_month = '" . self::OF_MONTH_YES . "'");
            $criteriaCondition->addCondition("category_id = '$category->id'");
            $criteriaCondition->addCondition("archive = '" . self::ARCHIVE_NO . "'");

            //Объединяем критерии
            $criteriaCompare->mergeWith($criteriaCondition);

            $products = Product::model()->findAll($criteriaCompare);

It throws an error.... CDbCommand failed to execute SQL query: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'archive' in where clause is ambiguous.
Separate requests work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-04-24
@ImPuuLsE

criteriaCondition->addColumnCondition(['t.archive'=>self::ARCHIVE_NO]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question