-
-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No proper pagination support with query builder #2823
Comments
Sounds exactly like what edit: The plan was to actually make this flag implicit if you join to-many relation in QB. |
QueryFlag.PAGINATE is not an option because it's usable only inside |
You can use it with QB too via |
Seems like adding |
Then please provide details for that. I am not going to add skip/take, I don't see a reason for different API doing the same thing, instead I do want to enable this paginate flag based on what is joined. Looking at |
Minimal pagination interface looks like this:
We need I just discovered that if I call it like this:
then it works the way I need. I suppose it could do this distinct wrapping automatically. |
You will need a separate call to get the total number of results, I hope we don't need to argue about that. I know there are some driver specific ways to do it in a single query (in mysql at least), tried it some time ago and it is much worse performance wise than a separate query.
There is a second boolean argument to enable disctinct query, in both I am still waiting for details regarding what is not working with paginate + order by. |
Right, I didn't notice that second arg at first. So About
This query fails if I call
It's not critical because I can move |
Yeah, that sounds reasonable. So to wrap up, the paginate flag works fine (except this one thing), and we can close this issue with enabling it by default when we detect to-many join? |
Right. Thanks for your help. |
I'm currently migrating from TypeORM and I've found that MikroORM lacks pagination support for QueryBuilder. Well, it works, until I need to add any
leftJoinAndSelect()
.There are a few issues actually (when we add
leftJoinAndSelect()
):getCount()
returns wrong countlimit()
also limits joined relationsorderBy()
causes SQL error (when used with or withoutgroupBy()
)Using
findAndCount()
orQueryFlag.PAGINATE
is not an option for me.Let's imagine such a simple example:
And imagine that we have 2 users, each of them has 10 comments.
Query 1:
Query 2:
Query 3. Let's try adding
orderBy()
:Query 4. Let's add
groupBy()
:That's it. TypeORM handles pagination nicely with their
skip()
andtake()
that we should use instead oflimit()
andoffset()
if we have at least oneleftJoinAndSelect()
on the query builder. They wrap the count query intoSELECT COUNT(DISTINCT("user"."id")) as "cnt" FROM (...main query here...)
and also do an additional query without limits to avoid limiting joined relations (though I don't know all the details).Is there some way around these issues right now?
Versions
The text was updated successfully, but these errors were encountered: