You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm trying to use the work done here #4740 to query a virtual entity based on a QueryBuider query (in my case a group by with some conditions).
I created an EntitySchema with an expression that returns a QueryBuilder but soon realized that it's being included inside a subquery which I don't want because the where clause I pass through the expression is also passed to the nesting query (here and here) which doesn't work in my case as the properties filtered in the first query don't exist in the virtual entity and the result of the subquery, and thus Postgres rejects it.
I tried to simply return the Promise object as a result but then the test checking if the result is an object is too naive and is catching the result as a Promise is also an object.
So I'm stuck with this query unless there is another way to get the result of this SQL in a virtual entity:
SELECT job_id, count(id) as count
FROM job
WHERE job_owner ='bob'-- the condition here is dynamic and can be more complexGROUP BY job_id
Finally for instance here is the full query it is generating:
Ideally, fix all to allow more flexibility, but at least (1).
Another solution would be to not pass the where clause to the sub-query here but that might break other use cases and is still sub-optimal as I don't need/want to have a sub-query.
Happy to discuss other ways that I may have overlooked.
Additional context
This is blocking me from producing some reporting features.
The text was updated successfully, but these errors were encountered:
So it's not gonna be that simple, we can't await the expression as that would mean executing the QB, both knex and the ORM query builder can be awaited directly. So 1. is not an option, but we can do 2. which will work out the same as you wanted.
@B4nan You were faster than me on this, I started a PR and through unit testing found as well that await doesn’t work, there are at least 2 other places that fail. Testing for promise did work with no regression on the unit tests. I was going to submit the PR later today.
Is your feature request related to a problem? Please describe.
I'm trying to use the work done here #4740 to query a virtual entity based on a QueryBuider query (in my case a
group by
with some conditions).I created an EntitySchema with an expression that returns a QueryBuilder but soon realized that it's being included inside a subquery which I don't want because the
where
clause I pass through the expression is also passed to the nesting query (here and here) which doesn't work in my case as the properties filtered in the first query don't exist in the virtual entity and the result of the subquery, and thus Postgres rejects it.I wanted then to use the last line of the findFromVirtual function to return my data directly from the virtual entity by executing the query (see the commented
qb.execute
above), but the expression is not evaluated in an async context and thus I cannotawait
the result.I tried to simply return the Promise object as a result but then the test checking if the result is an object is too naive and is catching the result as a Promise is also an object.
So I'm stuck with this query unless there is another way to get the result of this SQL in a virtual entity:
Finally for instance here is the full query it is generating:
Which fails with the error:
- column g0.score does not exist
(the last line above)Describe the solution you'd like
Either fix (1) this to
await
on the expression or fix (2) this to ignorePromises
(and type https://github.com/mikro-orm/mikro-orm/blob/master/packages/knex/src/AbstractSqlDriver.ts#L223 as maybe aPromise
) or add an option to not wrap the QueryBuilder in a subquery (3) hereIdeally, fix all to allow more flexibility, but at least (1).
Another solution would be to not pass the where clause to the sub-query here but that might break other use cases and is still sub-optimal as I don't need/want to have a sub-query.
Happy to discuss other ways that I may have overlooked.
Additional context
This is blocking me from producing some reporting features.
The text was updated successfully, but these errors were encountered: