Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlDataProvider makes error, if used with pagination #20224

Closed
DMGPage opened this issue Jul 10, 2024 · 0 comments
Closed

SqlDataProvider makes error, if used with pagination #20224

DMGPage opened this issue Jul 10, 2024 · 0 comments
Milestone

Comments

@DMGPage
Copy link
Contributor

DMGPage commented Jul 10, 2024

What steps will reproduce the problem?

Create SqlDataProvider, like this:

new SqlDataProvider([
    'sql' => Companies::find(), // it will react same with any sql. Just use any class, that you have
    'pagination' => ['pageSize' => 10]
]);

What is the expected result?

SqlDataProvider class.

What do you get instead?

Call to a member function getQueryBuilder() on string in
vendor/yiisoft/yii2/db/Query.php:157
Stack trace:
#0
vendor/yiisoft/yii2/db/Query.php(481):
yii\db\Query->createCommand()
#1
vendor/yiisoft/yii2/db/Query.php(368):
yii\db\Query->queryScalar()
#2
vendor/yiisoft/yii2/data/SqlDataProvider.php(170):
yii\db\Query->count()
#3
vendor/yiisoft/yii2/data/BaseDataProvider.php(174):
yii\data\SqlDataProvider->prepareTotalCount()
#4
vendor/yiisoft/yii2/data/BaseDataProvider.php(225):
yii\data\BaseDataProvider->getTotalCount()
#5
vendor/yiisoft/yii2/base/Component.php(180):
yii\data\BaseDataProvider->setPagination()
#6
vendor/yiisoft/yii2/BaseYii.php(557):
yii\base\Component->__set()
#7
vendor/yiisoft/yii2/base/BaseObject.php(107):
yii\BaseYii::configure()

Additional info

Q A
Yii version 2.0.50
PHP version PHP 8.3.8
Operating system Ubuntu 20.04 LTS (GNU/Linux 5.4.0-40-generic x86_64)

As far as I understand this issue appeared after version 2.0.50. If I downgrade it to 2.0.48 everything works fine and no issue on my example. After 2.0.50 somehow init function is not called and $this->db is left as string.

@samdark samdark added this to the 2.0.51 milestone Jul 10, 2024
@samdark samdark closed this as completed Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants