© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
2 replies
403gtfo

Noob question: Sorting a hasMany column in table

I'm really struggle sorry and I am sure it is dead easy to do.
Apologies, I know I've asked a bunch of relation questions, but that seems to be where stuff explodes for me.

What I am trying to do:
I need the HIndex column in the Activities table to be sortable based on the related HIndex with the highest year value (or based on the formatted state would be even better)

Model Activity:
- has many HIndex via
public function hIndices()
    {
        return $this->hasMany(HIndex::class)->orderBy('year', 'desc');
    }
public function hIndices()
    {
        return $this->hasMany(HIndex::class)->orderBy('year', 'desc');
    }


Model HIndex :
- Belongs to one Activity
- Has the columns
-- year
-- value
-- activity_id

In the Activity resource I have:
TextColumn::make('hIndices.value')
->formatStateUsing(function ($record) {
// ... some stuff dont worry about it
}
->sortable(),
TextColumn::make('hIndices.value')
->formatStateUsing(function ($record) {
// ... some stuff dont worry about it
}
->sortable(),


But it throws:
SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Sorting a table with a view as a column
FilamentFFilament / ❓┊help
3y ago
Issue with Sorting a Summed Relationship Column in Filament Table
FilamentFFilament / ❓┊help
12mo ago
relationship sorting in table
FilamentFFilament / ❓┊help
3y ago
Defaultsort / column sorting
FilamentFFilament / ❓┊help
3y ago