-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Update documentation to recommend DQL over QueryBuilder when possible #7880
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
Conversation
1f8b787
to
7dd506c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small wording reviews, nothing fundamental, but I hope it helps :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
7dd506c
to
9d07080
Compare
9d07080
to
d1db065
Compare
LGTM, good work, @kuraobi! |
|
||
But the ``QueryBuilder`` is not an alternative to DQL, it actually generates DQL | ||
queries at runtime, which are then interpreted by Doctrine. This means that | ||
using the ``QueryBuilder`` to build and run a query is actually always slower |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand you want to convince people to not use QueryBuilder, using performance as a reason sounds funny in the context of an ORM. A few method calls is totally negligible and not measurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally, but I think some people might be using the QB because they think it's more performant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That paragraph was my idea, but I'll make a PR to amend it if more people think it's irrelevant. I I still like it because it teaches people about the internals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point here is to explain that the QB is an extra layer that comes at a cost. Coding choices are based on trade offs, and I'm just emphasizing that performance wouldn't be in the "+" column. A lot of people think the QB is preferable because Doctrine doesn't need to parse DQL, but it's not true.
Fixes #7520
As explained in the related issue, the idea here is to promote usage of DQL over
QueryBuilder
when writing static queries. While theQueryBuilder
helps dynamically building DQL, it brings complexity to the code, so it should only be used when it actually brings value compared to DQL.While the
QueryBuilder
could be argued to bring abstraction, the real abstraction is DQL itself, and theQueryBuilder
does not bring more abstraction to writing queries.I tried to clarify the intent of both DQL and the
QueryBuilder
, so please tell me if you think my update is clear enough or not, and I'll update the PR accordingly.