Crud: [Bug] ListOperation orderByRaw does not work when using mongodb

Created on 26 Aug 2020  路  7Comments  路  Source: Laravel-Backpack/CRUD

Bug report

What I did

Tried to open a panel
??

What I expected to happen

To Open the panel
??

What happened

Mongodb Bad Sort Exception
??

What I've already tried to fix it

Commenting:
$this->crud->query->orderByRaw($this->crud->model->getTableWithPrefix().'.'.$column['name'].' '.$column_direction);
at list operation works.

Before when it had '$this->crud->query->orderBy($column['name'], $column_direction);'
It also worked (was change on one of last updates)

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 7.4.9 (cli) (built: Aug 4 2020 11:51:50) ( NTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

LARAVEL VERSION:

v6.18.36@0fc371134524190fdf31f77c77bc73b096760f18

BACKPACK VERSION:

4.1.19@a47eeda32d08d0d47a3c820416c8a8f880752b80

Bug triage

Most helpful comment

Sorry for my delay been super bussy last hours. Raw Expressions fail when changing from relational to non relational database cause there are no sql at mongodb so they dont understand whats going on when making raw queries.

I took out the prefix inside the raw method and did not work, also tried different values for the method too.

I believe the package mongodb users use for implementing the elloquent interface called laravel-mongodb (by jessengers) does not implement a solution for raw functions since they are pure (or almost pure) sql sintax and not something the elloquent interface could fix. (Correct me if I'm wrong)

I know you have in mind just sql langages and its ok since Laravel does the same thing... but backpack been working like a charm with the laravel-mongodb package before, and I have been surprised that cruds read nested documents and everything perfectly.

Tomorrow I'll check this again at my project, print error stack and post it here.

All 7 comments

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps _a lot_ in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (_How do I do X_) - Gitter Chatroom;
  • Long questions (_I have done X and Y and it won't do Z wtf_) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome _awesome_ community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

I changed the List Operation to the old version (making a new SearchTrait) for my cruds that use MongoDb with
Laravel-Mongodb and it seems to work fine

Ugh... thanks for reporting this @lborrazas . I was worried this would happen... We're on it. Could you please share a screenshot of the error stack? What's wrong here - does Eloquent not support orderByRaw when using MongoDB... OR is it a problem with the table prefix that we introduced?

I'm wondering if we can't find a better solution rather than littering the operation with an if/else statement depending on DBMS...

Hey @lborrazas

Like @tabacitu said we work with mysql support in mind, but if we can make it available for mongodb or other db engine we would happilly do it.

I am not a mongodb user, I think neither @tabacitu . It would help us to implement a solution for mongo if we better know the root of the problem.

Does orderByRaw work with mongo? Is the getTableWithPrefix() call that triggers the error ?

If any other mongodb user could also give his input it would be much appreciated.

Best,
Pedro

Sorry for my delay been super bussy last hours. Raw Expressions fail when changing from relational to non relational database cause there are no sql at mongodb so they dont understand whats going on when making raw queries.

I took out the prefix inside the raw method and did not work, also tried different values for the method too.

I believe the package mongodb users use for implementing the elloquent interface called laravel-mongodb (by jessengers) does not implement a solution for raw functions since they are pure (or almost pure) sql sintax and not something the elloquent interface could fix. (Correct me if I'm wrong)

I know you have in mind just sql langages and its ok since Laravel does the same thing... but backpack been working like a charm with the laravel-mongodb package before, and I have been surprised that cruds read nested documents and everything perfectly.

Tomorrow I'll check this again at my project, print error stack and post it here.

I'v just submited a PR that might address this. #3259

Let's keep the discussion of how we are going to implement it in the PR thread.

I am going to close this in favor of the PR.

Wish you the best,
Pedro

Just reviewed it, looks like a good solution, just had a few minor code style suggestions. Looks like we're going to have this merged by Monday @lborrazas .

Was this page helpful?
0 / 5 - 0 ratings