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

Referencing same object multiple times before flushing #181

Open
lavoiesl opened this issue Mar 23, 2015 · 0 comments
Open

Referencing same object multiple times before flushing #181

lavoiesl opened this issue Mar 23, 2015 · 0 comments
Labels

Comments

@lavoiesl
Copy link
Member

Copied from doctrine/DoctrineFixturesBundle#57 by @deeky666

I just encountered a problem with referencing an object multiple times with different names before flushing. It seems only the first reference I make gets persisted and is available in following fixtures. Here is an example:

public function load(ObjectManager $manager)
{
        $obj = new Obj();
        $obj->setFoo('bar');

        $manager->persist($obj);

        $this->addReference('first-reference', $obj);
        $this->addReference('second-reference', $obj);

        $manager->flush();
}

When referencing "first-reference" in the following fixture I get the persisted object I expect. But if I reference "second-reference" I get an object that is in an unpersisted state. This is problematic if I want to relate the previously persisted object to another object in a following fixture by referencing "second-reference".

If I flush before adding the references, everything works fine. Is it a bug or an intended behaviour?

@lavoiesl lavoiesl added the Bug label Mar 23, 2015
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

1 participant