8000 Add QueryBuilder vs DQL section · symfony/symfony-docs@011505e · GitHub
[go: up one dir, main page]

Skip to content

Commit 011505e

Browse files
committed
Add QueryBuilder vs DQL section
Describe difference between QueryBuilder and DQL usage
1 parent 6fc096e commit 011505e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

book/doctrine.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,10 @@ covered later), group, etc. For more information, see the official
766766
Querying for Objects Using Doctrine's Query Builder
767767
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
768768

769-
Instead of writing a DQL string, you can alternatively use a helpful object called
770-
the ``QueryBuilder`` to build that string for you::
769+
Instead of writing a DQL string, you can use a helpful object called the
770+
``QueryBuilder`` to build that string for you. This is usefull when the actual query
771+
depends on dynamic conditions, as your code soon becomes hard to read with
772+
DQL as you start to concatenate strings::
771773

772774
$repository = $this->getDoctrine()
773775
->getRepository('AppBundle:Product');
@@ -791,6 +793,14 @@ normal ``Query`` object, which can be used to get the result of the query.
791793
For more information on Doctrine's Query Builder, consult Doctrine's
792794
`Query Builder`_ documentation.
793795

796+
DQL vs Query Builder
797+
~~~~~~~~~~~~~~~~~~~~
798+
799+
When the actual query depends on dynamic conditions, your code soon becomes hard
800+
to read as you start to concatenate strings. In these cases, it's better to use
801+
the Doctrine QueryBuilder which provides a fluent interface to dynamically add
802+
every part of the query.
803+
794804
.. _book-doctrine-custom-repository-classes:
795805

796806
Custom Repository Classes

0 commit comments

Comments
 (0)
0