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

Spatie Translatable Listing column searchable exception in sql query when searching #9649

Closed
dev3k opened this issue Nov 14, 2023 · 5 comments · Fixed by #9732
Closed

Spatie Translatable Listing column searchable exception in sql query when searching #9649

dev3k opened this issue Nov 14, 2023 · 5 comments · Fixed by #9732
Labels
bug Something isn't working low priority unconfirmed

Comments

@dev3k
Copy link
Contributor

dev3k commented Nov 14, 2023

Package

filament/filament

Package Version

v3.0.95

Laravel Version

v10.31.0

Livewire Version

v3.1.0

PHP Version

PHP 8.2.9

Problem description

When you search a translatable column I get the following error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'json_extract(title, "$.en")' in 'where clause'

SELECT count(*) AS aggregate FROM `posts` WHERE (`json_extract(title, "$`.`en")` LIKE %AA%)

Expected behavior

it should be like

SELECT count(*) AS aggregate FROM `posts` WHERE json_extract(`title`, "$.en") LIKE '%AA%'

Steps to reproduce

just visit
http://json-column.test/admin/posts?tableSearch=AA

Reproduction repository

https://github.com/dev3k/json-column

Relevant log output

No response

@dev3k dev3k added bug Something isn't working low priority unconfirmed labels Nov 14, 2023
@dev3k
Copy link
Contributor Author

dev3k commented Nov 14, 2023

similar to #7537

@dev3k
Copy link
Contributor Author

dev3k commented Nov 16, 2023

I did some debugging and found this c89f86b PR #8784

search_collation always return null on mysql

$databaseConnection->getConfig('search_collation')

to make it work it should've been 'collation' instead of 'search_collation'

$databaseConnection->getConfig('collation')

I dont know why it's 'search_collation' maybe postgres ? I never used it before 😄

Screenshot 2023-11-16 at 8 42 31 PM

@Ahmant
Copy link
Contributor

Ahmant commented Nov 17, 2023

Hello,
Same issue here.

But to address the issue (until it is resolved by the package), I performed the search query independently, as follows:

public static function table(Table $table): Table
{
    $activeLocale = $table->getLivewire()->activeLocale ?? 'en'; // 👈 Here

    return $table
        ->columns([
            TextColumn::make('title')
                // 👇 Here
                ->searchable(query: fn (Builder $query, string $search) => $query->whereRaw("JSON_EXTRACT(LOWER(title), '$.$activeLocale') LIKE LOWER('%$search%')")) // 👈 Here
        ])
}

@zumbidoweb
Copy link

zumbidoweb commented Nov 17, 2023

+1

Screenshot 2023-11-17 at 12 19 51 PM

@inalto
Copy link
Contributor

inalto commented Nov 18, 2023

please look @ my pull request #9732

this fixed the issue for me

@danharrin danharrin linked a pull request Nov 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority unconfirmed
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants