doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.77k stars 224 forks source link

CircularReferenceException #232

Closed nursultanturdaliev closed 8 years ago

nursultanturdaliev commented 8 years ago

Guys I having an issue while trying to load fixtures for an entity with a tree behavior. You can see my entity on gist. Did anyone have issue like this and how did you solve it?

Ocramius commented 8 years ago

See similar issues, like https://github.com/doctrine/data-fixtures/issues/230, https://github.com/doctrine/data-fixtures/issues/231

Closing as duplicate.

nursultanturdaliev commented 8 years ago

@Ocramius It looks like not a duplicate issue. #230 , #231 don't deal with a circular reference error as shown below: [Doctrine\Common\DataFixtures\Exception\CircularReferenceException] Graph contains cyclic dependency. An example of this problem would be the following: Class C has class B as its dependency. Then, class B has class A has its dependency. Finally, class A h as class C as its dependency.

I am getting this error because of self-referencing properties like:

/**
     * @Gedmo\TreeParent
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
     * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
     */
    private $parent;

    /**
     * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
     * @ORM\OrderBy({"lft" = "ASC"})
     */
    private $children;
Ocramius commented 8 years ago

Are you already on 1.2.1? We fixed that in https://github.com/doctrine/data-fixtures/pull/229, as far as I know

nursultanturdaliev commented 8 years ago

@Ocramius thanks 👍 . My version was 1.2.0. Just updated and it's working fine.

kraimbaud commented 8 years ago

I have the same problem, but I'm using the 1.2.1. How can I fix that? Here is my Entity: Gist PS: I'm using alice bundle to load my fixture.

PorridgeBear commented 8 years ago

Also ran into this problem today with a self-referencing ManyToOne property. Also using 1.2.1 and whilst we normally use Alice, too, the issue also present when running the standard doctrine:fixtures:load.