@@ -91,11 +91,6 @@ abstract class Relation extends Field implements Form
9191 */
9292 protected ?Closure $ aggregateResolver = null ;
9393
94- /**
95- * Determine whether the relation values are aggregated.
96- */
97- protected bool $ aggregated = false ;
98-
9994 /**
10095 * The option group resolver.
10196 */
@@ -390,7 +385,7 @@ public function resolveDisplay(Model $related): ?string
390385 */
391386 public function getValue (Model $ model ): mixed
392387 {
393- if ($ this ->aggregated ) {
388+ if (is_callable ( $ this ->aggregateResolver ) ) {
394389 return parent ::getValue ($ model );
395390 }
396391
@@ -412,11 +407,14 @@ public function resolveFormat(Request $request, Model $model): ?string
412407 $ this ->formatResolver = function (Request $ request , Model $ model ): mixed {
413408 $ default = $ this ->getValue ($ model );
414409
415- if ($ this ->aggregated ) {
416- return $ default ;
410+ if (is_callable ( $ this ->aggregateResolver ) ) {
411+ return ( string ) $ default ;
417412 }
418413
419- return Collection::wrap ($ default )->map (fn (Model $ related ): ?string => $ this ->formatRelated ($ request , $ model , $ related ))->filter ()->join (', ' );
414+ return Collection::wrap ($ default )
415+ ->map (fn (Model $ related ): ?string => $ this ->formatRelated ($ request , $ model , $ related ))
416+ ->filter ()
417+ ->join (', ' );
420418 };
421419 }
422420
@@ -540,8 +538,6 @@ public function aggregate(string $fn = 'count', string $column = '*'): static
540538 $ column === '* ' ? '' : sprintf ('_%s ' , $ column )
541539 ));
542540
543- $ this ->aggregated = true ;
544-
545541 return $ query ->withAggregate ($ this ->getRelationName (), $ column , $ fn );
546542 };
547543
0 commit comments