Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4 Fixtures with Nelmio Alice not persisting

I am having trouble with Data Fixtures with Alice in Symfony 4.

When I run bin/console doctrine:fixtures:load I get asked if I want to purge the db and eventually the command terminates without any errors.

The database gets effectively purged but no data is populated.

I am using Symfony 4.0.3, Doctrine Data Fixtures 1.3 and Nelmio Alice 3.1.3.

src/DataFixtures/ORM/fixtures.yml

App\Entity\User:
user{1..10}:
    email: '<email()>'

src/DataFixtures/ORM/LoadFixtures.php

namespace App\DataFixtures\ORM;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Nelmio\Alice\Loader\NativeLoader;


class LoadFixtures extends Fixture
{
    public function load(ObjectManager $manager)
    {
        $loader = new NativeLoader();
        $objectSet = $loader->loadFile(__DIR__.'/fixtures.yml');

    }
}

src/Entity/User.php

namespace App\Entity;

use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User implements UserInterface
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;
    /**
     * @ORM\Column(type="string", unique=true)
     */
    private $email;

    ... and then various getters/setters methods

I suspect that the issue is with the data not getting persisted with the ObjectManager. Unfortunately there is no information whatsoever on the Nelmio/Alice's documentation about how the data can be persisted. https://github.com/nelmio/alice#table-of-contents

How can I make sure that the data get's persisted?

like image 338
Martin Avatar asked Jan 12 '18 16:01

Martin


1 Answers

    class LoadFixtures extends Fixture
{
    public function load(ObjectManager $manager)
    {
        $loader = new Nelmio\Alice\Loader\NativeLoader();
        $objectSet = $loader->loadFile(__DIR__.'/Fixtures.yml')->getObjects();
        foreach($objectSet as $object) {
            $manager->persist($object);
        }
        $manager->flush();
    }
}

Alice has changed a lot since version 3.

like image 70
slk500 Avatar answered Sep 22 '22 12:09

slk500