Mastering Doctrine Relations
Discover the magic of Doctrine Relations in Symfony: Learn to create ManyToOne and ManyToMany relations and querying with Joins.
About this course
In the part 1 of the Doctrine Tutorial we got some serious work done with Doctrine: creating entity classes, making custom queries, migrations, Docker setup & more!
But... we ignored one of the biggest part of Doctrine: relations / associations! And thanks to tooling inside of Symfony, creating database relationships - ManyToOne, ManyToMany, etc - has never been easier. So let's go!
- Generating a ManyToOne relationship (association)
- Relation annotations / PHP 8 attributes
- The OneToMany inverse side of a relation
- Handling relationships in fixtures with Foundry
- The owning versus inverse sides of a relation
- Doing magic with the ArrayCollection (Criteria)
- Querying with Joins
- ManyToMany Relations
So let's cook up some relationships and take our Cauldron Overflow app to the next level!
Next courses in the Symfony 5: The Fundamentals section of the Symfony 5 Track!
16 Comments
Hey Ilya,
Thank you for your interest in SymfonyCasts tutorials! This course should be the next after "Symfony UX: Turbo" that is releasing right now. I think this should happen in about 2 weeks.
Thank you for your patience!
Cheers!
Yup! I'm building it this week - Turbo had a few more chapters than I expected. I'm hoping to release this next week :)
Looking forward to it! These doctrine courses are the reason I got a subscription. I'm currently working on a massive warehouse management database and my implementation of foundry for testing is incredibly hacky
Hey Nick F.!
> Looking forward to it! These doctrine courses are the reason I got a subscription
Sweet!
> my implementation of foundry for testing is incredibly hacky
We won't be talking about Foundry and testing in this tutorial. But if you have any specific questions, I'd be happy to do my best to answer them here :).
Cheers!
Is there a mistake in the course description then? One of the topics is "Handling relationships in fixtures with Foundry"
Oh, yes! We will cover that - just not using Foundry specifically inside of tests :).
Ok, it'll release NEXT week actually - but right away on Monday, then we'll move through quickly. Thanks for your patience on this one - I had some "things" come up personally that were straining my work time!
Hi, Would you deal with connections to multiple databases and make:migration/doctrine:migration:migrate to multiple databases (I don't know if this one is possible ...) ?
Hey Lionel,
Unfortunately, Maker bundle only generates migrations for MySQL database. But in case you have configured multiple connections to multiple DB in your project, you can use DoctrineMigrationBundle's commands, e.g. "bin/console doctrine:migrations:diff --conn=CONN" Where CONN is your connection. Or just add --help option to any Symfony command to see more options that you can use. I believe the --conn option is exactly what you need in your case.
I hope this helps!
Cheers!
Hello victor , Doctrine Migrations also generate migrations for PostgreSQL.
Hey Abdelkarim,
Yes, DoctrineMigrationsBundle does, but Maker does not IIRC :)
Cheers!
Hey Abdelkarim,
Ah, really? I didn't know :) IIRC it didn't at some point in time. Thanks for confirming it works, then it's an easy win with Maker as well
Cheers!
Hello, when is the release date? Can't wait... =)