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!
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!