F
Filament8mo ago
Shavik

SelectFIlter & AsEnumCollection

I have a model Caliber. It has a casts like this:
public function casts(): array
{
return [
'unit_system' => UnitSystems::class,
'types' => AsEnumCollection::of(CaliberTypes::class),
];
}
public function casts(): array
{
return [
'unit_system' => UnitSystems::class,
'types' => AsEnumCollection::of(CaliberTypes::class),
];
}
I then have a SelectFilter on the table like so:
->filters([
Tables\Filters\SelectFilter::make('types')
->multiple()
->options(CaliberTypes::class),
])
->filters([
Tables\Filters\SelectFilter::make('types')
->multiple()
->options(CaliberTypes::class),
])
The table works/looks fine: (see attached image) But when I try to filter the table, I get an SQL error. Using PostgreSQL 14.
SELECT
count(*) AS aggregate
FROM
"calibers"
WHERE
("types" IN (pistol))
SELECT
count(*) AS aggregate
FROM
"calibers"
WHERE
("types" IN (pistol))
Since the column is a jsonb I can see why it doesn't like this. SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type json DETAIL: Token "pistol" is invalid. CONTEXT: JSON data, line 1: pistol unnamed portal parameter $1 = '...' I could convert to using a 'caliber_types' table but given these types should never really change, it seems like overkill. Any thoughts? Posting this and stepping away for dinner real fast. Will check in as soon as I get back.
No description
10 Replies
awcodes
awcodes8mo ago
But Postgres is so good. Lol. Jk.
Shavik
ShavikOP8mo ago
I switched out to sqlite and it doesn't throw an 'error' anymore, but the search results are wrong / it 'ignores' the filter
Shavik
ShavikOP8mo ago
No description
Shavik
ShavikOP8mo ago
No description
awcodes
awcodes8mo ago
Weird. The db matters. As much as I hate it. Had this happen today where a script drops foreign key constraints for a migration, but the syntax is relevant for sqlite vs MySQL. So frustrating.
Shavik
ShavikOP8mo ago
Shavik
ShavikOP8mo ago
This is using sqlite
awcodes
awcodes8mo ago
Yea. I was trying to port MySQL to sqlite but sqlite doesn’t know ‘set’ lol. At least as a function with the DB facade.
Shavik
ShavikOP8mo ago
Was trying to find if this is a eloquent problem, a laravel problem, or a filament problem lol It could be a 'me' problem too but I don't believe so..
awcodes
awcodes8mo ago
Definitely a db problem. DB::statement('SET FOREIGN_KEY_CHECKS=0;'); definitely throws an error with sqlite. Lol.
Want results from more Discord servers?
Add your server