Doctrine, Symfony & the Database

41:19

What you'll be learning

It's database time! After the first two courses, we are primed and ready to take our app up a level... or 10!

This tutorial is all about Doctrine: a powerful ORM that will allow us to talk to a database from inside our Symfony app. Historically, Doctrine has sometimes had a reputation for being hard to learn. But with recent changes in the Symfony world, that's gone. You are going to love what Doctrine will let you do! Let's go!

  • Booting a database with Docker via make:docker:database
  • Database Configuration
  • 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 Foundry
  • Relationships & Associations

Your Guides

Ryan Weaver

Buy Access

Questions? Conversation?

  • 2020-08-05 Andres M

    Hi Ryan, thanks for your response. I have never had used it until yesterday and thought it could be up and working like the other two types. Not the case :)
    I'll go with Symfony cache instead and take advantage of Tags for invalidations.

    I'm waiting for the Doctrine course to be fully released, meanwhile I have a couple in my bookmarks to have fun, keep on with the great content!

  • 2020-08-05 kibria4

    Hi @weweaverryan !

    Well I am a beginner to Microservices and DDD pattern so I'm studying about making each service a business domain and then connecting them together with a gateway. Some of the things I'd like to know about are merging data together from each service that have relations and how authentication and authorization works in a microservices architecture. For my upcoming project, I am required to to build a SaaS system that manages shift rotations and keeping a group of users' documents up to date. Due to the size of the business and the features they require, a Microservices architecture is most probably necessary, especially as different groups of users will be using different sections of the system.

    I think these topics may be good to help beginners get started on Microservices with Symfony:

    - Create a few individual services in Symfony (or API Platform)
    - Relationships between services
    - API Gateway built in Symfony to connect them, or maybe something that's already out there that is easy to work with, like Tyk (I tried Kong and that was quite a headache to get it running!)
    - Authentication and authorization
    - Possibly service health check to make sure developers are notified when a service is down or can cause problems to other services
    - A frontend to communicate with the backend

    I'm having trouble thinking of what should be covered afterwards as not all parts are related to Symfony per se. Now that I think about it, deployment is a big and tricky section as there are multiple hosting providers and each will have their own configuration methods. If I can think of anything else that could help shape a Microservices course on SymfonyCasts, I'll let you know!

  • 2020-08-05 weaverryan

    Hi Andres M!

    Yes, you're right! So, there are 3 different types of caches in Doctrine: metadata, query and result caches. The first 2 - metadata & cache - make complete sense to have enabled all the time in production - they cache the Doctrine annotations and how it *builds* the queries (not the results). But thanks to the prod config that you get out-of-the-box - https://github.com/symfony/... - this is already configured for you. So, you don't need to think about it.

    The 3rd type of cache - result cache - is something that you need to opt into when you make a query. Basically, you tell Doctrine: "please cache the result of this query". I've actually *never* used it before. There's not a problem with it, but since Symfony already has a great cache system, if I need to cache anything (whether it's data from Doctrine or some other data) I put that data into Symfony's cache system. It's one cache system for anything I need :). We use it in our Symfony fundamentals course: https://symfonycasts.com/sc...

    So that's why you don't see anything here :). But if you have any questions or doubts, let me know!

    Cheers!

  • 2020-08-05 weaverryan

    Hey @kibria4!

    As Diego mentioned, those topics *are* already on our list, but not officially being worked on. But since you are already studying them, I would *love* to know what specifically you're interested in about each of them - especially microservices, which can be a *huge* topic (communicating between microservices, deployment, authentication, organizing a micro Symfony app, just to mention a few things that come to mind quickly). That's one of the reasons I haven't talked microservices here on SymfonyCasts yet (even though we have 3 microservices that operate behind our main site): I'm not *exactly* sure what parts are most important to people.

    Cheers!

  • 2020-08-04 Andres M

    Hi guys, i don't see any cache dedicated chapter. Are you going to include that topic in any other chapter?

  • 2020-08-04 kibria4

    Thanks for getting back to me!

    Awesome, I'm happy that they are being considered :) hopefully they will come soon

  • 2020-08-04 Diego Aguiar

    Hey!

    We're so glad to hear that you find our tutorials useful. At this point we do not have planned to create a tutorial about DDD or microservices but those are topics that we have in mind. This kind of feedback help pushing forward the release of those tutorials :)

    Cheers!

  • 2020-08-04 kibria4

    Hi!

    First of all, I'd like to thank you all at SymfonyCasts for your awesome courses! They have helped me so much with a number of projects I've been working on, especially the way things are explained has helped me understand on a deeper level on what a specific feature is and when to use it.

    Secondly, I LOVE that you are using Docker now. I have a hard time working with Docker and with the quality of your content thus far, I have a feeling that I will have a better understanding in the tutorials to come.

    Finally, I was just wondering if there will be courses released in relation to Microservices and/or Domain-Driven Design at some point. Currently I'm resorting to reading up on ASP.NET Core and Laravel to build a new project I will need to work on in the coming months.

  • 2020-08-03 weaverryan

    Hey Alberto!

    I just uploaded one this morning - it should be out tomorrow. Then we'll hit the gas on this tutorial :). I was out last week for vacation, which is why the first 2 chapters came out this week, but none yet. Oh, and *technically* the release date is tomorrow even for the first chapters - (that's when we'll announce them on Twitter). We've tweaking our process to get videos released to people on the site more quickly (e.g. last week) even if the official release date for a tutorial or chapter isn't until later :).

    Cheers!

  • 2020-08-03 Alberto

    hey, new week and no episodes yet

  • 2020-07-31 Victor Bocharsky

    Hey Mike,

    Yes, unfortunately, no course about microservices yet, but that's a really good topic and we would really like to release a course about it in the future. This topic is in our ideas pool, but I don't have estimations yet when it might be released, sorry. There're a lot of good stuff that we would like to release before start working on this course.

    I'm sorry to hear that it's slow for you, but I assure you that we're doing our best on releasing the content. Usually, our solid release schedule is release one video a day. Sometimes we can release a few videos at once, it depends on our progress. Releasing our videos is a complex process, and sometimes it's not clear why 5-minute video takes so long to be released behind the scene. We're doing a lot of planning and draft coding, then we create scripts and record video and audio, then we postpone the video adding some cool animation effects and exclude long pauses to make the video as short as possible, combine audio and video, etc. And finally, we're adding dynamic code blocks to the scripts so you can see the exact code we are using in the course. I completely understand that you want to get videos faster, but that's our best pace we can move for now.

    > This tutorials are released so slow that when one is finished a new version is already out

    Haha, sometimes that happens :) Well, if we're talking about minor version - most probably it's a coincident ;) If you're talking about patch versions - yeah, that happens of course, depends on the package activity on GitHub. If major version changed - that's a totally bad luck, but usually we avoid such thing, I don't remember when it even happens :) Yes, our courses are releasing in full not in one day, but usually within a month we're completing our tutorials in progress as our statistics show. Our releasing policy is to deliver content as quickly as it's ready. We don't want users to wait 1 month before releasing the course in full the same day. Instead, we release a video or few per day so that our users may watch it faster.

    I hope this sheds the light on our release process and is more reasonable for you now. Thank you for your patience and understanding!

    Cheers!

  • 2020-07-31 Mike

    This tutorials are released so slow that when one is finished a new version is already out ...
    And you guys do not talk about biggest topics like microservices... no wonder Laravel is taken more serious when it comes to this... You can find all kind of resources on the topic...

  • 2020-07-29 Alberto

    thank's

  • 2020-07-29 Diego Aguiar

    Hey Alberto

    This course is at the oven right now! Only one more week and it will be ready to be consumed ;)

  • 2020-07-29 Alberto

    release now please! jajaja

  • 2020-07-29 Alberto

    when?????

  • 2020-07-27 Vladimir Sadicov

    Maybe yes, maybe no, stay tuned!

    Cheers!

  • 2020-07-25 Aaron Kincer

    Any chance this weekend?

  • 2020-07-21 Victor Bocharsky

    Hey Guido,

    Done! FYI, you can edit *your* Disqus comments yourself as well in 7 days after posted them, see "Edit" link below your comments ;)

    Cheers!

  • 2020-07-21 Guido

    Will have a look, thank you!

  • 2020-07-20 Diego Aguiar

    Hey Guido

    Currently we don't have a complex case where you show how to manage it with DTO's but you can watch this video to get a better idea of how to do it https://symfonycasts.com/sc...

    Also, you may find interesting this talk from SymfonyCon 2018 about rich forms https://symfonycasts.com/sc...

    I hope it helps!

  • 2020-07-20 Guido

    Sorry, the link contains a ")" at the end (please delete this).

  • 2020-07-20 Guido

    Hello Ryan,

    first: Thank you for you amazing work!

    Many sources say that you should not directly link entities and forms ( https://stackoverflow.com/a... ). This includes ocramius as a doctrine developer. But the Symfony documentation still propagates this. So I would be interested to see more complex examples. Often you will find only one form with 2-3 fields in these examples, but no more complex many-to-many entities are involved.
    I would like to see some "best practices" here.

  • 2020-07-20 weaverryan

    Hey Guido!

    Not in this tutorial - DTO's aren't really related to Doctrine - they are more important depending on *how* you want to use them - like DTO's in the form component or DTO's with API Platform. What is your interest with DTO's?

    Cheers!

  • 2020-07-20 Guido

    Will you talk about data transfer objects?

  • 2020-07-17 weaverryan

    I just finished the video recording! So Victor is right - 2 weeks or, hopefully, sooner :)

  • 2020-07-17 Victor Bocharsky

    Hey Mdev,

    We're actively working on it right now! I think it should be started releasing in about 2 weeks.

    Thank you for your patience!

    Cheers!

  • 2020-07-17 mdev

    Is there a known ETA-ish for this course?

  • 2020-07-15 Victor Bocharsky

    Hey k_e_v ,

    Haha, check this tweet, guys! https://twitter.com/weaverr...

    Cheers!

  • 2020-07-15 k_e_v

    Was wondering the same thing lol

  • 2020-07-08 Victor Bocharsky

    Hey Vladimir,

    Haha, stay tuned to know something new! ;) We will start releasing this very soon.

    Cheers!

  • 2020-07-07 Vladimir Light

    whats is Foundry O.o ?