doctrine / data-fixtures

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

Fixtures won't load when using self-referencing relation #245

Closed mikemix closed 7 years ago

mikemix commented 7 years ago

Using version 1.2.1 the issue #228 is still there with this set up:

/**
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string")
 * @ORM\DiscriminatorMap({
 *     "super1" = "AppBundle\Entity\Super1",
 *     "super2" = "AppBundle\Entity\Super2"
 * })
 * @ORM\Table
 */
abstract class Super
{
    /**
     * var self
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Super", inversedBy="revisions")
     * @ORM\JoinColumn(name="parent_id", nullable=true)
     */
    private $parent;

    /**
     * @var self[]
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Super", mappedBy="parent")
     */
    private $revisions;
}

Error when trying to load the fixtures:

[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 has class C as its dependency

The schema mapping is ok, the relation is working too.

mikemix commented 7 years ago

Example above works well with latest master.

NeilJ247 commented 7 years ago

Related to https://github.com/doctrine/data-fixtures/pull/229. dev/master works.

mikeSimonson commented 7 years ago

Fix in the last release https://github.com/doctrine/data-fixtures/releases/tag/v1.2.2

Thanks