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),
    ];
}


I then have a SelectFilter on the table like so:
->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))


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.
image.png
Was this page helpful?