Doctrine & the Database

Buy Access

Two episodes down! Booya! And we are super ready to put our new skills to the test! It's finally time to make up app come alive by using Doctrine to connect to a database.

Doctrine is an amazing ORM that works great with Symfony and is super powerful. It also has a reputation for being hard to learn and for making you write a lot of code. But that's changing! Thanks to some recent improvements and Symfony Flex, working with Doctrine has never been easier or more rewarding. So, let's get started!

  • Creating (and updating) Entities with make:entity
  • Generating & using migrations
  • Inserting new data
  • Fetching & Querying for data
  • Doctrine Repositories
  • Custom queries and the query builder
  • Fixtures (Dummy data) using Faker
  • Relationships & Associations

Your Guides

Ryan Weaver

Questions? Conversation?

  • 2018-06-04 weaverryan

    Hey Sławek Grochowski!

    GREAT question. I was having that same thought after writing it this way :). If I were to recreate this function to be more flexible, I would probably just force the user to do this step. So, it would look more like this:

    $this->createMany(10, function($i) {
    $article = new Article();
    // ...

    return $article;

    Then, the createMany() function would look at the class of the object that was returned to know how to store it as a reference :). I think this is just as easy, but more flexible.


  • 2018-06-02 Sławek Grochowski

    function createMany is pretty nice, but what about Entities which require arguments in constructor?

  • 2018-04-23 Victor Bocharsky

    Hey Prout,

    Yes, we have the one but in Symfony 3 track. This course was recorded in a Symfony 4 way using Flex and our new "The Spacebar" Symfony 4 project.


  • 2018-04-22 Prout

    I thought there was already a "Doctrine & the Database Tutorial". Is it an update ?

  • 2018-04-20 Diego Aguiar

    Hey Hermen

    Haha, you "may" be lazy but it's our fault as well. For some reason it wasn't added to the track, but I just did it!
    Thanks for reporting it :)

    Have a nice day

  • 2018-04-20 Hermen

    Why is this course not listed in the Symfony 4 track? I have a hard time finding it (or I'm just lazy)...

  • 2018-02-20 weaverryan

    Hey Mauro!

    Yea, these commands are still being updated to work with Symfony 4. The big issue is actually pretty simple: you don't have a bundle in Symfony 4 :). Here are some more details:

    So, as you can see there, right now, there are some workarounds, like temporarily creating a bundle. But pretty soon, I hope it will be updated to work without a bundle.


  • 2018-02-16 Mauro

    Hi guys,
    how can i import an existing database in Symfony 4?
    In Symfony3 you can do:

    php bin/console doctrine:mapping:import --force AppBundle xml
    php bin/console doctrine:generate:entities AppBundle
    php bin/console doctrine:mapping:convert annotation ./src

    but those commands don't work in Symfony4.


  • 2018-02-13 weaverryan

    Hey ali nizar!

    You can read about all of that here: The configuration in that article will need to be a bit different to support environment variables, but hopefully it will get you started. For autowiring all the entity managers, I would use a bind rule ( to bind to argument names - like $adminEntityManager if you had an em called "admin".


  • 2018-02-13 weaverryan

    Hey Peter Kosak!

    This is next in the Symfony series - and I want to get it out soon. But, it will be at least several weeks, for two reasons. First, we'll release the Webpack Encore & React tutorials first. And second, there's a pull request on MakerBundle that we really *need* for this tutorial. So, it needs to be merged and released still. But I'll try to get it all done as quickly as possible :).


  • 2018-02-13 ali nizar

    how can i use Multiple Entity Managers and mutiple databases

  • 2018-02-13 Peter Kosak

    When will be this course available? Cant wait