F
Filament2mo ago
Groli

Issue with Select field and relationships

Hello, After upgrading to v4 some functionality broke and I'm not able find the issue with migration docs... It concerns this Select field in my form:
Select::make('course_id')
->label('Course')
->relationship('course')
->getOptionLabelFromRecordUsing(fn (Course $record) => CourseQuery::formatTitle($record))
->getSearchResultsUsing(CourseQuery::search(...))
->searchable()
->visible(fn (Get $get) => $get('room_type_id') == 2),
Select::make('course_id')
->label('Course')
->relationship('course')
->getOptionLabelFromRecordUsing(fn (Course $record) => CourseQuery::formatTitle($record))
->getSearchResultsUsing(CourseQuery::search(...))
->searchable()
->visible(fn (Get $get) => $get('room_type_id') == 2),
when I have it like this and try to search, no updates are triggered (no searching), I tried removing relationship method and then it started to search (updates triggered) but then I couldn't save the data. Can someone help me figure out what is the breaking change that made this stop working after migration? Thanks in advance for any help.
6 Replies
Groli
GroliOP2mo ago
My bad, I just fired up old version and it doesn't work there either, what am I doing wrong?
Dan Harrin
Dan Harrin2mo ago
if you overwrite getSearchResultsUsing, you have to call the getOptionLabel part yourself the default implementation of getSearchResultsUsing from the relationship() method does that, but you overwrote it
Groli
GroliOP2mo ago
Select::make('course_id')
->label('Course')
->relationship('course', modifyQueryUsing: CourseQuery::transform(...))
->getOptionLabelFromRecordUsing(fn (Course $record) => CourseQuery::formatTitle($record))
->searchable()
->visible(fn (Get $get) => $get('room_type_id') == 2),
Select::make('course_id')
->label('Course')
->relationship('course', modifyQueryUsing: CourseQuery::transform(...))
->getOptionLabelFromRecordUsing(fn (Course $record) => CourseQuery::formatTitle($record))
->searchable()
->visible(fn (Get $get) => $get('room_type_id') == 2),
the transform implementation:
public static function transform(Builder $query, ?string $search): Builder
{
$query->with('teacherPeople');

if ($search) {
self::applyConstraints($query, $search);
}

self::applySort($query);

return $query;
}
public static function transform(Builder $query, ?string $search): Builder
{
$query->with('teacherPeople');

if ($search) {
self::applyConstraints($query, $search);
}

self::applySort($query);

return $query;
}
I tried getting rid of search result modification and use the relationship, but still no triggers... Did I get wrong, what you've tried to get across to me?
No description
No description
Groli
GroliOP2mo ago
so now i'm not even using it, and still nothing...
Dan Harrin
Dan Harrin2mo ago
Please open an issue with a reproduction repository
Groli
GroliOP2mo ago
I'll do it later today, thanks for now...

Did you find this page helpful?