@@ -722,6 +722,33 @@ instead of querying for rows on a table (e.g. ``product``).
722
722
When querying in Doctrine, you have two options: writing pure Doctrine queries
723
723
or using Doctrine's Query Builder.
724
724
725
+ Querying for Objects with DQL
726
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727
+
728
+ Instead of using the ``QueryBuilder ``, you can alternatively write the queries
729
+ directly using DQL::
730
+
731
+ $em = $this->getDoctrine()->getManager();
732
+ $query = $em->createQuery(
733
+ 'SELECT p
734
+ FROM AppBundle:Product p
735
+ WHERE p.price > :price
736
+ ORDER BY p.price ASC'
737
+ )->setParameter('price', '19.99');
738
+
739
+ $products = $query->getResult();
740
+
741
+ If you're comfortable with SQL, then DQL should feel very natural. The biggest
742
+ difference is that you need to think in terms of "objects" instead of rows
743
+ in a database. For this reason, you select *from * the ``AppBundle:Product ``
744
+ *object * and then alias it as ``p `` (as you see, this is equal to what you
745
+ already did in the previous section).
746
+
747
+ The DQL syntax is incredibly powerful, allowing you to easily join between
748
+ entities (the topic of :ref: `relations <book-doctrine-relations >` will be
749
+ covered later), group, etc. For more information, see the official
750
+ `Doctrine Query Language `_ documentation.
751
+
725
752
Querying for Objects Using Doctrine's Query Builder
726
753
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727
754
@@ -759,33 +786,6 @@ is no result) or ``getOneOrNullResult()``::
759
786
For more information on Doctrine's Query Builder, consult Doctrine's
760
787
`Query Builder `_ documentation.
761
788
762
- Querying for Objects with DQL
763
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
764
-
765
- Instead of using the ``QueryBuilder ``, you can alternatively write the queries
766
- directly using DQL::
767
-
768
- $em = $this->getDoctrine()->getManager();
769
- $query = $em->createQuery(
770
- 'SELECT p
771
- FROM AppBundle:Product p
772
- WHERE p.price > :price
773
- ORDER BY p.price ASC'
774
- )->setParameter('price', '19.99');
775
-
776
- $products = $query->getResult();
777
-
778
- If you're comfortable with SQL, then DQL should feel very natural. The biggest
779
- difference is that you need to think in terms of "objects" instead of rows
780
- in a database. For this reason, you select *from * the ``AppBundle:Product ``
781
- *object * and then alias it as ``p `` (as you see, this is equal to what you
782
- already did in the previous section).
783
-
784
- The DQL syntax is incredibly powerful, allowing you to easily join between
785
- entities (the topic of :ref: `relations <book-doctrine-relations >` will be
786
- covered later), group, etc. For more information, see the official
787
- `Doctrine Query Language `_ documentation.
788
-
789
789
.. _book-doctrine-custom-repository-classes :
790
790
791
791
Custom Repository Classes
0 commit comments