Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractExecutor clearing ObjectManager after every load() #162

Open
rafaame opened this issue Sep 7, 2014 · 6 comments
Open

AbstractExecutor clearing ObjectManager after every load() #162

rafaame opened this issue Sep 7, 2014 · 6 comments
Labels

Comments

@rafaame
Copy link

rafaame commented Sep 7, 2014

https://github.com/doctrine/data-fixtures/blob/master/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php#L122

In a project of mine I have a case of two dependent fixtures in which the ObjectManager should not have been cleared between their load(). I think it would be better if we don't call $manager->clear() if we are in case of dependent fixtures (or at least have an option to avoid that), what do you think @Ocramius ?

@stof
Copy link
Member

stof commented Sep 8, 2014

why shouldn't it be cleared ? The ReferenceRepository already takes care of giving you a managed instance when getting the reference back

@tiger-seo
Copy link

it should not be cleared because of this

    public function getReference($name)
    {
        $reference = $this->references[$name];
        $meta = $this->manager->getClassMetadata(get_class($reference));
        $uow = $this->manager->getUnitOfWork();
        if (!$uow->isInIdentityMap($reference) && isset($this->identities[$name])) {
            $reference = $this->manager->getReference(
                $meta->name,
                $this->identities[$name]
            );
            $this->references[$name] = $reference; // already in identity map
        }
        return $reference;
    }

the manager being used by reference repository and the one used by loader is the same, so it is influencing directly and causing ORM to load entity every time

@stof
Copy link
Member

stof commented Nov 21, 2014

@tiger-seo if the UoW is not cleared, Computing the changeset in each fixture files requires checking all previously loaded entities for changes. This is why clearing the EntityManager has been added.

and note that getReference will not load the entity. It creates a proxy for it. So depending on the way you use your reference, it is totally possible that Doctrine never needs to load it in your new fixture (if all it needs is the id, for instance when adding it in a collection)

@tiger-seo
Copy link

but it does loading, at least for associations

@stof
Copy link
Member

stof commented Nov 21, 2014

depends what you are doing with your associations

@tiger-seo
Copy link

if your entity has composite identity from association than you will not be able to persist them with out intermediate flush

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

No branches or pull requests

4 participants