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:Jump to solution
try remove
modifyQueryUsing
this works for me
```php
NumberConstraint::make('likes_count')
->relationship('likes', 'id')...3 Replies
Solution
try remove
modifyQueryUsing
this works for me
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?
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.