Skip to content
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

Place DQL in front of QueryBuilder again #5022

Closed
wouterj opened this issue Feb 19, 2015 · 2 comments
Closed

Place DQL in front of QueryBuilder again #5022

wouterj opened this issue Feb 19, 2015 · 2 comments
Labels
actionable Clear and specific issues ready for anyone to take them. Doctrine good first issue Ideal for your first contribution! (some Symfony experience may be required) hasPR A Pull Request has already been submitted for this issue.

Comments

@wouterj
Copy link
Member

wouterj commented Feb 19, 2015

A year ago, we decided to move the QueryBuilder section above the DQL section for the following reason:

I tend to use (and recommend) the query builder normally. If we showed that first, the DQL section could then be a bit of an afterthought - like "Oh, and if you want to control things a bit more yourself, you can use this DQL thing".

However, I would propose to revert this to DQL before QueryBuilder now. For some reason:

  • QueryBuilder adds an abstraction that isn't needed
  • Most people are more familair with the DQL (which is almost SQL) syntax than the QueryBuilder API
  • As soon as things get more complex than a simple SELECT ... FROM ... WHERE ..., QueryBuilder takes up more lines, has a strange API syntax and isn't easy to follow

On IRC, the first answer when someone asks something about the QueryBuilder is often "try DQL" and in 9 of the 10 cases, it solves the issue. Besides this, once a week someone joins and asks "how can I do this SQL with QueryBuilder?"

I recently had a discussion about when a query builder made sense and it was really hard to find a good situation. In fact, the only thing I can think of is in a case where the query is build dynamically (based on PHP statements) and isn't very complex.

@stof
Copy link
Member

stof commented Feb 21, 2015

The use case for the QueryBuilder is indeed for cases where you need to build the query dynamically (changing conditions based on arguments passed to the function, for instance), for which it becomes easier than heavy string manipulation.

@weaverryan
Copy link
Member

👍 for DQL first, followed by "hey, here's a nice object interface for this if you like it!".

The QB has some advantages, but users can easily grow into it if they like.

@wouterj wouterj added good first issue Ideal for your first contribution! (some Symfony experience may be required) actionable Clear and specific issues ready for anyone to take them. and removed needs comments labels May 8, 2015
@xabbuh xabbuh added the hasPR A Pull Request has already been submitted for this issue. label May 23, 2015
weaverryan added a commit that referenced this issue May 25, 2015
This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #5302).

Discussion
----------

Place DQL in front of QueryBuilder

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.7
| Fixed tickets | #5022

Commits
-------

2335206 Update doctrine.rst
ce9456c Place DQL in front of QueryBuilder
@wouterj wouterj closed this as completed May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. Doctrine good first issue Ideal for your first contribution! (some Symfony experience may be required) hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

4 participants