Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update documentation to recommend DQL over QueryBuilder when possible#7880

Merged
Ocramius merged 1 commit into
doctrine:2.6from
kuraobi:update-doc-dql-qb
Oct 29, 2019
Merged

Update documentation to recommend DQL over QueryBuilder when possible#7880
Ocramius merged 1 commit into
doctrine:2.6from
kuraobi:update-doc-dql-qb

Conversation

@kuraobi
Copy link
Copy Markdown

@kuraobi kuraobi commented Oct 28, 2019

Fixes #7520

As explained in the related issue, the idea here is to promote usage of DQL over QueryBuilder when writing static queries. While the QueryBuilder 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 the QueryBuilder 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.

Copy link
Copy Markdown
Contributor

@Pierstoval Pierstoval left a 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 :)

Comment thread docs/en/reference/query-builder.rst Outdated
Comment thread docs/en/reference/working-with-objects.rst Outdated
Copy link
Copy Markdown
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Comment thread docs/en/reference/faq.rst Outdated
Comment thread docs/en/reference/query-builder.rst
Comment thread docs/en/reference/query-builder.rst
Comment thread docs/en/reference/query-builder.rst Outdated
Comment thread docs/en/reference/query-builder.rst
@Ocramius Ocramius added this to the 2.6.5 milestone Oct 29, 2019
@Ocramius Ocramius self-assigned this Oct 29, 2019
@Ocramius
Copy link
Copy Markdown
Member

LGTM, good work, @kuraobi!

@Ocramius Ocramius dismissed SenseException’s stale review October 29, 2019 18:03

Review comments handled

@Ocramius Ocramius merged commit e9e012a into doctrine:2.6 Oct 29, 2019
Comment thread docs/en/reference/faq.rst

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
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants