Doctrine Collections: ManyToMany, Forms & other Complex Relations

2:24:59

What you'll be learning

This course is built on Symfony 3, but most of the concepts apply just fine to newer versions of Symfony.
// composer.json
{
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.1.*", // v3.1.4
        "doctrine/orm": "^2.5", // v2.7.2
        "doctrine/doctrine-bundle": "^1.6", // 1.6.4
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
        "symfony/swiftmailer-bundle": "^2.3", // v2.3.11
        "symfony/monolog-bundle": "^2.8", // 2.11.1
        "symfony/polyfill-apcu": "^1.0", // v1.2.0
        "sensio/distribution-bundle": "^5.0", // v5.0.22
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
        "incenteev/composer-parameter-handler": "^2.0", // v2.1.2
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "knplabs/knp-markdown-bundle": "^1.4", // 1.4.2
        "doctrine/doctrine-migrations-bundle": "^1.1", // 1.1.1
        "stof/doctrine-extensions-bundle": "^1.2" // v1.2.2
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0", // v3.0.7
        "symfony/phpunit-bridge": "^3.0", // v3.1.3
        "nelmio/alice": "^2.1", // 2.1.4
        "doctrine/doctrine-fixtures-bundle": "^2.3" // 2.3.0
    }
}

With the basic of Doctrine relations behind us, it's time to dive deeper and get our hands dirty with some real-world, but complex collections. Honestly, this is the hardest part of Doctrine: so let's get it right:

  • Creating ManyToMany associations
  • Querying on ManyToMany relations
  • Mapping the inverse (collection) side of a relation
  • (bonus) Using DoctrineExtension for clean URL slugs
  • Keeping the owning & inverse sides in-sync
  • Using orphanRemoval to delete items in a collection
  • Using cascade to save items in a collection
  • Counting collections in the EXTRA_LAZY way
  • Rendering relationship data from both sides
  • Filtering collections efficiently with Criteria (mind will be blown)
  • Dealing with complex collection forms
  • Adding "extra" data to the "join table"

Doctrine relationships take a little bit more work to get setup. So let's master this stuff, setup our relationships to win, and get back to work.


Your Guides

Ryan Weaver

Buy Access

Questions? Conversation?