@@ -766,8 +766,10 @@ covered later), group, etc. For more information, see the official
766
766
Querying for Objects Using Doctrine's Query Builder
767
767
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
768
768
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::
771
773
772
774
$repository = $this->getDoctrine()
773
775
->getRepository('AppBundle:Product');
@@ -791,6 +793,14 @@ normal ``Query`` object, which can be used to get the result of the query.
791
793
For more information on Doctrine's Query Builder, consult Doctrine's
792
794
`Query Builder `_ documentation.
793
795
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
+
794
804
.. _book-doctrine-custom-repository-classes :
795
805
796
806
Custom Repository Classes
0 commit comments