F
Filament3mo ago
Arjan

QueryBuilder with an relationship->counts()

Hi, I am using this column with a count of related Assets (hasMany relationship) in my table: TextColumn::make('assets_count') ->numeric() ->label('Assets') ->counts('assets'), I now want to make a filter for this column using Querybuilder: NumberConstraint::make('assets_count') ->relationship( name: 'assets', titleAttribute: 'id', modifyQueryUsing: fn(Builder $query) => $query->count(), ) ->label("Assets"), However this NumberContraint is not working and throws this error: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "series" LINE 1: select count() as aggregate from "assets" where "series"."i... ^ SELECT count() AS aggregate FROM "assets" WHERE "series"."id" = "assets"."series_id" Please help! Thanks!
Solution:
try remove modifyQueryUsing this works for me ```php NumberConstraint::make('likes_count') ->relationship('likes', 'id')...
Jump to solution
3 Replies
Solution
Lara Zeus
Lara Zeus3mo ago
try remove modifyQueryUsing this works for me
NumberConstraint::make('likes_count')
->relationship('likes', 'id')
->integer(),
NumberConstraint::make('likes_count')
->relationship('likes', 'id')
->integer(),
Arjan
Arjan3mo ago
Hi Lara, Thanks for your answer. The error is now gone indeed. But the filtering is not working. Example with value 2 is minimum, all rows with only 1 assets are still displayed. See screenshot. Any advise?
No description
Arjan
Arjan3mo ago
By the way this is happening with all my NumberContraint filters. So it seems to be a different issue. I will create a new topic, and mark your solution as correct.