Hey guys. I have some problem with relations. Tried to sort by field which is accessible via ->hasMany()->one()->ofMany()->some_field For example I have 2 models - Channel and ChannelPost A Channel has many ChannelPost. A ChannelPost have
views
views
field with count of views. Now in Channel model I have this relations:
/** * @return HasMany */ public function posts(): HasMany { return $this->hasMany(ChannelPost::class); } /** * @return HasOne */ public function lastPost(): HasOne { return $this->posts()->one()->ofMany('post_id', 'max'); }
/** * @return HasMany */ public function posts(): HasMany { return $this->hasMany(ChannelPost::class); } /** * @return HasOne */ public function lastPost(): HasOne { return $this->posts()->one()->ofMany('post_id', 'max'); }
In Filament table I use
Tables\Columns\TextColumn::make('lastPost.views')
Tables\Columns\TextColumn::make('lastPost.views')
When I tried to sort by this field - it was sorted randomly.
So I tried to find the problem and did some debugging.