yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework

Home Page:http://www.yiiframework.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Closures in Querys no longer possible since 2.0.51-dev

SusanneWaletzko opened this issue · comments

What steps will reproduce the problem?

I have some search models in legacy code that are using closures. Worked fine until update on 2.0.51-dev

What is the expected result?

Search model contains something like

$query = User::find(); 
$dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
// confederationId
 if ($this->confederationId) {
         $query->joinWith(['userProfile' => function ($q) {
                $q->andFilterWhere(['user_profiles.confed_id' => $this->confederationId]);
         }]);
 }

expected search query to be extended and search by e.g. "confederationId"

What do you get instead?

Exception
Serialization of 'Closure' is not allowed
1. in ..../releases/893/vendor/yiisoft/yii2/db/Query.php at line 1399
139013911392139313941395139613971398139914001401        ]);
    }
 
    /**
     * Returns the SQL representation of Query
     * @return string
     */
    public function __toString()
    {
        return serialize($this);
    }
}

Additional info

In 2.0.50

seems not to be used?

Q A
Yii version 2.0.51-dev
PHP version 8.1.28
Operating system
commented

It seems that method \yii\db\Query::__toString() has never been used.