Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Mastering Doctrine Relations

2:45:18

What you'll be learning

This tutorial also works great for Symfony 6!
// composer.json
{
    "require": {
        "php": "^7.4.1 || ^8.0.0",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "babdev/pagerfanta-bundle": "^3.3", // v3.3.0
        "composer/package-versions-deprecated": "^1.11", // 1.11.99.3
        "doctrine/doctrine-bundle": "^2.1", // 2.4.2
        "doctrine/doctrine-migrations-bundle": "^3.0", // 3.1.1
        "doctrine/orm": "^2.7", // 2.9.5
        "knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
        "knplabs/knp-time-bundle": "^1.11", // v1.16.1
        "pagerfanta/doctrine-orm-adapter": "^3.3", // v3.3.0
        "pagerfanta/twig": "^3.3", // v3.3.0
        "sensio/framework-extra-bundle": "^6.0", // v6.2.1
        "stof/doctrine-extensions-bundle": "^1.4", // v1.6.0
        "symfony/asset": "5.3.*", // v5.3.4
        "symfony/console": "5.3.*", // v5.3.7
        "symfony/dotenv": "5.3.*", // v5.3.7
        "symfony/flex": "^1.3.1", // v1.17.5
        "symfony/framework-bundle": "5.3.*", // v5.3.7
        "symfony/monolog-bundle": "^3.0", // v3.7.0
        "symfony/runtime": "5.3.*", // v5.3.4
        "symfony/stopwatch": "5.3.*", // v5.3.4
        "symfony/twig-bundle": "5.3.*", // v5.3.4
        "symfony/validator": "5.3.*", // v5.3.14
        "symfony/webpack-encore-bundle": "^1.7", // v1.12.0
        "symfony/yaml": "5.3.*", // v5.3.6
        "twig/extra-bundle": "^2.12|^3.0", // v3.3.1
        "twig/string-extra": "^3.3", // v3.3.1
        "twig/twig": "^2.12|^3.0" // v3.3.2
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
        "symfony/debug-bundle": "5.3.*", // v5.3.4
        "symfony/maker-bundle": "^1.15", // v1.33.0
        "symfony/var-dumper": "5.3.*", // v5.3.7
        "symfony/web-profiler-bundle": "5.3.*", // v5.3.5
        "zenstruck/foundry": "^1.1" // v1.13.1
    }
}

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!


Your Guides

Ryan Weaver

Buy Access

Join the Conversation?

16
Login or Register to join the conversation
Ilya E. Avatar
Ilya E. Avatar Ilya E. | posted 1 year ago

Hello, when is the release date? Can't wait... =)

Reply

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!

2 Reply
Nick-F Avatar

Is this almost ready for launch?

Reply

Yup! I'm building it this week - Turbo had a few more chapters than I expected. I'm hoping to release this next week :)

Reply
Nick-F Avatar

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

1 Reply

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!

Reply
Nick-F Avatar

Is there a mistake in the course description then? One of the topics is "Handling relationships in fixtures with Foundry"

Reply

Oh, yes! We will cover that - just not using Foundry specifically inside of tests :).

Reply

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!

Reply
Lionel F. Avatar
Lionel F. Avatar Lionel F. | posted 1 year ago

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 ...) ?

Reply

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!

1 Reply

Hello victor , Doctrine Migrations also generate migrations for PostgreSQL.

Reply

Hey Abdelkarim,

Yes, DoctrineMigrationsBundle does, but Maker does not IIRC :)

Cheers!

Reply

maker works also with PosgreSQL ;)

Reply

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!

Reply
Lionel F. Avatar
Lionel F. Avatar Lionel F. | victor | posted 1 year ago

Ty I will ty this :)

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!