Closed mitchierichie closed 2 years ago
I was able to fix this by extending the AllowedFilter
and FiltersExact
classes, and overriding the isRelationProperty
method and removing an if statement:
protected function isRelationProperty(Builder $query, string $property): bool
{
if (!Str::contains($property, '.')) {
return false;
}
// removed this if statement
if (in_array($property, $this->relationConstraints)) {
return false;
}
$firstRelationship = explode('.', $property)[0];
if (!method_exists($query->getModel(), $firstRelationship)) {
return false;
}
return is_a($query->getModel()->{$firstRelationship}(), Relation::class);
}
This doesn't seem to have caused any errors, is this if statement required?
The other reasoning for this seems to be that in FiltersExact::withRelationConstraint()
, the whereHas
closure calls $this->__invoke
on the FiltersExact
instance, and there seems to be a reference issue where the same instance of FiltersExact
is getting used more than once.
This reference issue happens even if I clone the return value of AllowedFilter::exact
.
Laravel version: 8.78.1 PHP version: 8.0.10 Package version: 4.0.2
I'm trying to filter by a related column on more than one query per request lifecycle, and then I'm using union on the resulting QueryBuilder objects to run the queries at the same time.
For some reason I'm getting errors because this is my resulting query:
This is a long query and a little tough to read, so I've included the problem query (2nd of the 2 filtered queries) below:
You'll see the issue is that in this query, it's filtering by
'categories'.'slug'
but it's not adding anexists
clause, or selecting anything fromcategories
table, so I get acolumn not found
exception when this runs.Why doesn't the query builder generate the same SQL every time?