@@ -74,13 +74,24 @@ protected function setUp(): void
7474 /** @var HasMany | MorphMany $relationship */
7575 $ relationship = Relation::noConstraints (fn () => $ table ->getRelationship ());
7676
77- $ record = $ relationship ->getQuery ()->find ($ data ['recordId ' ]);
77+ $ relationshipQuery = $ relationship ->getQuery ();
78+
79+ if ($ this ->modifyRecordSelectOptionsQueryUsing ) {
80+ $ relationshipQuery = $ this ->evaluate ($ this ->modifyRecordSelectOptionsQueryUsing , [
81+ 'query ' => $ relationshipQuery ,
82+ 'search ' => null ,
83+ ]) ?? $ relationshipQuery ;
84+ }
85+
86+ $ record = $ relationshipQuery ->find ($ data ['recordId ' ]);
7887
7988 foreach (($ this ->isMultiple ? $ record : [$ record ]) as $ record ) {
80- if ($ record instanceof Model) {
81- $ this -> record ( $ record ) ;
89+ if (! $ record instanceof Model) {
90+ continue ;
8291 }
8392
93+ $ this ->record ($ record );
94+
8495 /** @var BelongsTo $inverseRelationship */
8596 $ inverseRelationship = $ table ->getInverseRelationshipFor ($ record );
8697
@@ -281,15 +292,35 @@ public function getRecordSelect(): Select
281292 ->multiple ($ this ->isMultiple ())
282293 ->searchable ($ this ->getRecordSelectSearchColumns () ?? true )
283294 ->getSearchResultsUsing (static fn (Select $ component , string $ search ): array => $ getOptions (optionsLimit: $ component ->getOptionsLimit (), search: $ search , searchColumns: $ component ->getSearchColumns ()))
284- ->getOptionLabelUsing (function ($ value ) use ($ table ): string {
295+ ->getOptionLabelUsing (function ($ value ) use ($ table ): ? string {
285296 $ relationship = Relation::noConstraints (fn () => $ table ->getRelationship ());
286297
287- return $ this ->getRecordTitle ($ relationship ->getQuery ()->find ($ value ));
298+ $ relationshipQuery = $ relationship ->getQuery ();
299+
300+ if ($ this ->modifyRecordSelectOptionsQueryUsing ) {
301+ $ relationshipQuery = $ this ->evaluate ($ this ->modifyRecordSelectOptionsQueryUsing , [
302+ 'query ' => $ relationshipQuery ,
303+ 'search ' => null ,
304+ ]) ?? $ relationshipQuery ;
305+ }
306+
307+ $ record = $ relationshipQuery ->find ($ value );
308+
309+ return $ record ? $ this ->getRecordTitle ($ record ) : null ;
288310 })
289311 ->getOptionLabelsUsing (function (array $ values ) use ($ table ): array {
290312 $ relationship = Relation::noConstraints (fn () => $ table ->getRelationship ());
291313
292- return $ relationship ->getQuery ()->find ($ values )
314+ $ relationshipQuery = $ relationship ->getQuery ();
315+
316+ if ($ this ->modifyRecordSelectOptionsQueryUsing ) {
317+ $ relationshipQuery = $ this ->evaluate ($ this ->modifyRecordSelectOptionsQueryUsing , [
318+ 'query ' => $ relationshipQuery ,
319+ 'search ' => null ,
320+ ]) ?? $ relationshipQuery ;
321+ }
322+
323+ return $ relationshipQuery ->find ($ values )
293324 ->mapWithKeys (fn (Model $ record ): array => [$ record ->getKey () => $ this ->getRecordTitle ($ record )])
294325 ->all ();
295326 })
0 commit comments