Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

doctrine - clear in populator #1870

Closed
devozanges opened this issue Dec 6, 2019 · 2 comments
Closed

doctrine - clear in populator #1870

devozanges opened this issue Dec 6, 2019 · 2 comments

Comments

@devozanges
Copy link

greeting
when I have to make fixtures with relationships, the populator tells me that my entities are not persisted, so by searching in the Faker\ORM\Doctrine\Populator class, I found that there were orm->clear(), it's fine but it makes disappear the entities I join to my relationships so I'm obliged to comment on the clear() so that my fixtures work with relationships.
Do you know if there is a more conventional practice to achieve this?
Thanks for your work anyway

`public function execute($entityManager = null)
{
    if (null === $entityManager) {
        $entityManager = $this->manager;
    }
    if (null === $entityManager) {
        throw new \InvalidArgumentException("No entity manager passed to Doctrine Populator.");
    }

    $insertedEntities = [];
    foreach ($this->quantities as $class => $number) {
        $generateId = $this->generateId[$class];
        for ($i = 0; $i < $number; $i++) {

            $insertedEntities[$class][] = $this->entities[$class]->execute(
                $entityManager,
                $insertedEntities,
                $generateId
            );
            if (count($insertedEntities) % $this->batchSize === 0) {
                $entityManager->flush();
                // $entityManager->clear($class);
            }
        }
        $entityManager->flush();
        // $entityManager->clear($class);
    }
    return $insertedEntities;
}`
@jaapromijn
Copy link

jaapromijn commented Dec 9, 2019

I think this is a duplicate of #1862

@pimjansen
Copy link
Contributor

Indeed a duplicate

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants