Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3k stars 880 forks source link

[Bug + fix] Last MongoDB : toMql() instead >toSql() in CrudPanel/Traits/Query.php #5460

Open elgrosboub opened 4 months ago

elgrosboub commented 4 months ago

Bug report

Installed a fresh Laravel 10+ Last Backpack V6 + Last MongoDB Package (https://www.mongodb.com/compatibility/mongodb-laravel-integration)

What I expected to happen

Work.

What happened

When I change connection :

use MongoDB\Laravel\Eloquent\Model; protected $connection = 'mongodb';

I have error :

This method is not supported by MongoDB. Try "toMql()" instead. {"userId":1,"exception":"[object] (BadMethodCallException(code: 0): This method is not supported by MongoDB. Try \"toMql()\" instead. at //vendor/mongodb/laravel-mongodb/src/Query/Builder.php:1442) [stacktrace] #0 //vendor/backpack/crud/src/app/Library/CrudPanel/Traits/Query.php(220): MongoDB\Laravel\Query\Builder->toSql()

What I've already tried to fix it

When i change by ->toMql() instead >toSql() that work !

public function getFilteredQueryCount()
{
    // check if the filtered query is different from total query, in case they are the same, skip the count
    $filteredQuery = $this->query->toBase()->cloneWithout(['orders', 'limit', 'offset']);

    return $filteredQuery->toMql() !== $this->totalQuery->toMql() ? $this->getQueryCount() : null;
}

Is it a bug in the latest version of Backpack?

Yes

jcastroa87 commented 4 months ago

Hello @elgrosboub, thanks for bringing us this report about the issue; we will check about this change on the last version of MongoDB package and fix it.

I will ask the wise @pxpm to check this compatibility.

Cheers.