'Yii2 select2 database exception number of bound variables does not match number of tokens

when i use select2 widget in my yii 2 applicaton, it will cause the following error:

SQLSTATE [HY093]: Invalid parameter number: number of bound variables does not match number of tokens
The SQL being executed was: SELECT * FROM `page` WHERE `page`.`id`=6

The executed sql does not apply my override in find function of Page model as follow:

public static function find()
{
    return parent::find()->where(['websiteId' => Yii::$app->website->id]);
}

Debug stack hint me to beforeInsert() function in ActiveRecord at line 333 & this code:

$this->node->refresh();

Every thing seems ok, so whats wrong?



Solution 1:[1]

I had a same problem, It seems to be a bug in framework! Just find refresh() function & change the following line in vendor/yiisoft/yii2/db/ActiveRecord.php file

$query->where($pk);

to

$query->andWhere($pk);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman