Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Lens withCount and sortable field fails on sort #6592

Closed
FN-FAL113 opened this issue Nov 25, 2024 · 0 comments
Closed

Lens withCount and sortable field fails on sort #6592

FN-FAL113 opened this issue Nov 25, 2024 · 0 comments
Labels
blocked pending Issues that are pending triage

Comments

@FN-FAL113
Copy link

FN-FAL113 commented Nov 25, 2024

  • Laravel Version: 10
  • Nova Version: 4.35
  • PHP Version: 8.2
  • Database Driver & Version: MySQL 8.0.33 (Docker Image)
  • Operating System and Version: Windows 11
  • Browser type and version: MS Edge
  • Reproduction Repository:

Description:

When a query utilizes withCount and making a field sortable, the raw sql query that gets added by #sortable function prefixes an aliased subquery field with the table name which causes an error:
Error Code: 1054. Unknown column 'categories.products_count' in 'order clause'
image

I am not sure if the query is sql version dependent but I'm thinking that aliased fields should not be prefixed since its not a default table field.

Faulty

select `categories`.*, (select count(*) from `products` where `categories`.`id` = `products`.`category_id`) as `products_count` 
from `categories` order by `categories`.`products_count` asc;

Working

select `categories`.*, (select count(*) from `products` where `categories`.`id` = `products`.`category_id`) as `products_count` 
from `categories` order by `products_count` asc;

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Create lens class

  2. Define the query and filter just like in the image below and also making the aliased field sortable
    image

  3. Sort the field in the actual nova application in the browser

@FN-FAL113 FN-FAL113 changed the title Lense withCount and sortable field fails on sort Lens withCount and sortable field fails on sort Nov 25, 2024
@crynobone crynobone added blocked pending Issues that are pending triage labels Nov 25, 2024
@laravel laravel locked and limited conversation to collaborators Jan 2, 2025
@crynobone crynobone converted this issue into discussion #6645 Jan 2, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
blocked pending Issues that are pending triage
Projects
None yet
Development

No branches or pull requests

2 participants