@@ -6,12 +6,13 @@ Databases and Doctrine
66
77One of the most common and challenging tasks for any application
88involves persisting and reading information to and from a database. Although
9- the Symfony full-stack Framework doesn't integrate any ORM by default,
10- the Symfony Standard Edition, which is the most widely used distribution,
11- comes integrated with `Doctrine `_, a library whose sole goal is to give
12- you powerful tools to make this easy. In this chapter, you'll learn the
13- basic philosophy behind Doctrine and see how easy working with a database
14- can be.
9+ the Symfony Framework doesn't integrate any component to work with databases,
10+ it provides tight integration with a third-party library called `Doctrine `_.
11+ Doctrine's sole goal is to give you powerful tools to make database interactions
12+ easy and flexible.
13+
14+ In this chapter, you'll learn how to start leveraging Doctrine in your Symfony projects
15+ to give you rich database interactions.
1516
1617.. note ::
1718
@@ -609,6 +610,8 @@ repository object for an entity class via::
609610
610611Once you have a repository object, you can access all sorts of helpful methods::
611612
613+ $repository = $this->getDoctrine()->getRepository('AppBundle:Product');
614+
612615 // query for a single product by its primary key (usually "id")
613616 $product = $repository->find($productId);
614617
@@ -630,6 +633,8 @@ Once you have a repository object, you can access all sorts of helpful methods::
630633You can also take advantage of the useful ``findBy `` and ``findOneBy `` methods
631634to easily fetch objects based on multiple conditions::
632635
636+ $repository = $this->getDoctrine()->getRepository('AppBundle:Product');
637+
633638 // query for a single product matching the given name and price
634639 $product = $repository->findOneBy(
635640 array('name' => 'Keyboard', 'price' => 19.99)
@@ -712,6 +717,8 @@ Querying for Objects
712717You've already seen how the repository object allows you to run basic queries
713718without any work::
714719
720+ $repository = $this->getDoctrine()->getRepository('AppBundle:Product');
721+
715722 $product = $repository->find($productId);
716723 $product = $repository->findOneByName('Keyboard');
717724
@@ -792,6 +799,15 @@ normal ``Query`` object, which can be used to get the result of the query.
792799For more information on Doctrine's Query Builder, consult Doctrine's
793800`Query Builder `_ documentation.
794801
802+ Organizing Custom Queries into Repository Classes
803+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
804+
805+ All the queries in the previous sections were written directly in your controller.
806+ But for organization, Doctrine provides special repository classes that allow you
807+ to keep all your query logic in one, central place.
808+
809+ see :doc: `/doctrine/repository ` for info.
810+
795811Configuration
796812-------------
797813
@@ -811,19 +827,23 @@ the ``length``, ``nullable`` behavior, ``name`` and other options. To see a
811827list of all available types and more information, see Doctrine's
812828`Mapping Types documentation `_.
813829
814- Summary
815- -------
830+ Relationships and Associations
831+ ------------------------------
832+
833+ Doctrine provides all the functionality you need to manager database relationships
834+ (also known as associations). For info, see :doc: `/doctrine/associations `.
835+
836+ Final Thoughts
837+ --------------
816838
817- With Doctrine, you can focus on your objects and how they're used in your
839+ With Doctrine, you can focus on your * objects * and how they're used in your
818840application and worry about database persistence second. This is because
819841Doctrine allows you to use any PHP object to hold your data and relies on
820842mapping metadata information to map an object's data to a particular database
821843table.
822844
823- And even though Doctrine revolves around a simple concept, it's incredibly
824- powerful, allowing you to create complex queries and subscribe to events
825- that allow you to take different actions as objects go through their persistence
826- lifecycle.
845+ Doctrine has a lot more complex features to learn, like relationshps, complex queries,
846+ and event listeners.
827847
828848Learn more
829849~~~~~~~~~~
0 commit comments