Skip to content

Commit

Permalink
Merge pull request #12821 from filamentphp/fix/summarize-pivot-column…
Browse files Browse the repository at this point in the history
…-with-duplicate-name

fix: Summarize pivot column with duplicate name
  • Loading branch information
danharrin authored May 16, 2024
2 parents 53732cb + 147cf57 commit 3473a68
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/tables/src/Columns/Summarizers/Summarizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ function (EloquentBuilder $relatedQuery) use ($baseQuery, $query): EloquentBuild
return $relatedQuery;
},
);
} elseif (str($attribute)->startsWith('pivot.')) {
// https://github.com/filamentphp/filament/issues/12501

$pivotAttribute = (string) str($attribute)
->after('pivot.')
->prepend('pivot_');

$isPivotAttributeSelected = collect($query->getQuery()->getColumns())
->contains(fn (string $column): bool => str($column)->endsWith(" as {$pivotAttribute}"));

$attribute = $isPivotAttributeSelected ? $pivotAttribute : $attribute;
}

$asName = (string) str($query->getModel()->getTable())->afterLast('.');
Expand Down

0 comments on commit 3473a68

Please sign in to comment.