Howto use Doctrine repositories with migrations

Howto use Doctrine repositories with migrations

Howto use Doctrine repositories with migrations

No Comments on Howto use Doctrine repositories with migrations written by Hylke

Today I wanted to do something other than usual: I wanted to convert a couple of fields in my database and fill them automatically while doing the migration. Now I’ve done this before, create a preUp, save the data I need, and in the postUp convert this data to the new fields.

This day was a little different, because I needed a repository in my postUp, well, easy with Symfony 4: first thing I tried was use Dependancy Injection, but that failed:

  Too few arguments to function DoctrineMigrations\Version20190329145026::__construct(), 1 passed in /application/vendor/doctrine/migrations/lib/Doctrine/Migrations/Version/Version.php on line 65

It took me some time, but I found the thing I needed in a little corner of the Symfony documentation .

All I needed to do was use:

$uploadRepository = $this->container->get('doctrine')->getRepository(Upload::class);

in my postUp, and I was ready to roll.

Related Posts

Leave a Reply

Back to Top