Filter by related column only applying to one query per request lifecycle #721
Unanswered
mitchierichie
asked this question in
Q&A
Replies: 1 comment
-
I was able to fix this by extending the 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 This reference issue happens even if I clone the return value of |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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?
Beta Was this translation helpful? Give feedback.
All reactions