question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom order logic produces error with search

See original GitHub issue

Bug report

What I did

I created a custom order logic to order by a relationship field like the following:

return $query->leftJoin('users', 'users.id', '=', 'rooms.user_id')
                        ->orderBy('users.email', $columnDirection)->select('rooms.*');

What I expected to happen

I expect that it doesn’t affect any other functionality in the CRUD.

What happened

Whenever I do a search query in the CRUD while the sorting of that relationship field is triggered … I get the following error in the Ajax.

"SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select `rooms`.* from `rooms` left join `users` on `users`.`id` = `rooms`.`user_id` where (`id` like %a% or exists (select * from `users` where `rooms`.`user_id` = `users`.`id` and `email` LIKE %a%) or `bedrooms` like %a% or `bathrooms` like %a% or `roommates` like %a% or `gender` like %a% or `rent` like %a% or `plan` like %a% or `status` like %a%) and `rooms`.`deleted_at` is null order by `users`.`email` asc, `id` desc limit 10)"

If I remove the search query from the search field and try to order by the relationship column it works well.

What I’ve already tried to fix it

Tried to debug the issue and follow the documentation but no luck.

Backpack, Laravel, PHP, DB version

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

### PHP VERSION:
PHP 7.3.17 (cli) (built: Apr 16 2020 13:00:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.17, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.17, Copyright (c) 1999-2018, by Zend Technologies

### LARAVEL VERSION:
v5.8.38@78eb4dabcc03e189620c16f436358d41d31ae11f

### BACKPACK VERSION:
4.0.61@1977e0cc52fa7cf9547eaeadf03f5cd88402b574

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tabacitucommented, Jul 8, 2020

I agree @lilessam - if the package can handle that automatically, it should. So I’m going to put this on the list of things to do, thanks!

0reactions
tabacitucommented, Jul 9, 2020

I see @pxpm just submitted #3015 which fixes this, so let’s move the conversation there please! Thanks for raising the issue @lilessam !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom ORDER BY logic in an SQL query - Stack Overflow
My problem is that the client wants to special ordering - they wish to have entries with a certain value for the hgroup_id...
Read more >
Error handling - Apollo GraphQL Docs
You can create a custom errors and codes using the graphql package's GraphQLError ... Custom errors can provide additional context, enabling your clients...
Read more >
Sort records in custom order - Microsoft Support
Sort a large number of unique field values. If you have a large number of values to rank, a better way to sort...
Read more >
Terms aggregation | Elasticsearch Guide [8.5] | Elastic
This produces a bounded document count error that Elasticsearch can report. You can use the order parameter to specify a different sort order, ......
Read more >
CloudWatch search expression syntax - AWS Documentation
Explains the syntax rules for search expressions in a CloudWatch graph. ... SEARCH( 'NOT Namespace=AWS ', 'Maximum', 120) yields all your custom metrics ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found