Set default value for search, or how to resolve ID of a record in select
Hi,
I have select that corresponds to One-To-Many relationship and it stores ID of a related record in table of current model, for which form I'm trying to build...
But when user loads the page with already selected related record, only ID shows to him and it is not resolved in the
getSearchResultsUsing
. Do you know how would I be able to resolve this ID that shows to user, I was thinking maybe adding some default search value, but I don't know how to pass current record ID.
I provided images with current and expected behaviour.
Here is code for the Select:
I tried using:
but that didn't help.

Solution:Jump to solution
Make the course a relationship on the model and don't use ID. Then you can use ->relationship() on the select which will load everything as expected.
3 Replies
Solution
Make the course a relationship on the model and don't use ID. Then you can use ->relationship() on the select which will load everything as expected.
But I use custom searching and custom title creation for that model...
But adding
->relationship('course')
helped me to load the initial data... So thank you for help...And that's ok for searching, but key/name comes from the relation which is why it works.