1

I have a Circular Reference Exception because of Doctrine Tree Extension when I'm tring to load my fixture with Alice fixture.

[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.

I have found the same problem here: https://github.com/doctrine/data-fixtures/issues/232 but the solution does not work for me :( ...

I'm using this version of the doctrine fixtures.

"doctrine/data-fixtures": "1.2.1",

Here is my entity

namespace BaseBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;

    /**
     * BaseCategory
     *
     * @ORM\Entity()
     * @ORM\InheritanceType("JOINED")
     * @ORM\DiscriminatorColumn(name="type", type="string")
     * @ORM\DiscriminatorMap({
     *      "article_category" = "AppBundle\Entity\ArticleCategory",
     *      "page_category" = "AppBundle\Entity\PageCategory",
     *     })
     * @Gedmo\Tree(type="nested")
     */
    abstract class BaseCategory
    {
        use \BaseBundle\Traits\SeoTrait;

        /**
         * @var int
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;

        /**
         * @var string
         *
         * @ORM\Column(name="title", type="string", length=255)
         * @Assert\NotBlank()
         */
        private $title;

        /**
         * @var string
         *
         * @ORM\Column(name="slug", type="string", length=255, unique=true)
         * @Gedmo\Slug(fields={"title"})
         */
        private $slug;

        /**
         * @var string
         *
         * @ORM\Column(name="description", type="text")
         */
        private $description;

        /**
         * @var \DateTime
         *
         * @ORM\Column(type="datetime")
         * @Gedmo\Timestampable(on="create")
         */
        private $createdAt;

        /**
         * @var \DateTime
         *
         * @ORM\Column(type="datetime")
         * @Gedmo\Timestampable(on="update")
         */
        private $updatedAt;

        /**
         * @Gedmo\TreeLeft
         * @ORM\Column(type="integer")
         */
        private $lft;

        /**
         * @Gedmo\TreeLevel
         * @ORM\Column(type="integer")
         */
        private $lvl;

        /**
         * @Gedmo\TreeRight
         * @ORM\Column(type="integer")
         */
        private $rgt;

        /**
         * @Gedmo\TreeRoot
         * @ORM\ManyToOne(targetEntity="BaseCategory")
         * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
         */
        private $root;

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

        /**
         * @ORM\OneToMany(targetEntity="BaseCategory", mappedBy="parent")
         * @ORM\OrderBy({"lft" = "ASC"})
         */
        private $children;

        /**
         * Get id
         *
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }

        /**
         * Set title
         *
         * @param string $title
         *
         * @return BaseCategory
         */
        public function setTitle($title)
        {
            $this->title = $title;

            return $this;
        }

        /**
         * Get title
         *
         * @return string
         */
        public function getTitle()
        {
            return $this->title;
        }

        /**
         * Set slug
         *
         * @param string $slug
         *
         * @return BaseCategory
         */
        public function setSlug($slug)
        {
            $this->slug = $slug;

            return $this;
        }

        /**
         * Get slug
         *
         * @return string
         */
        public function getSlug()
        {
            return $this->slug;
        }

        /**
         * Set description
         *
         * @param string $description
         *
         * @return BaseCategory
         */
        public function setDescription($description)
        {
            $this->description = $description;

            return $this;
        }

        /**
         * Get description
         *
         * @return string
         */
        public function getDescription()
        {
            return $this->description;
        }

        /**
         * @return \DateTime
         */
        public function getCreatedAt()
        {
            return $this->createdAt;
        }

        /**
         * @return \DateTime
         */
        public function getUpdatedAt()
        {
            return $this->updatedAt;
        }

        public function getRoot()
        {
            return $this->root;
        }

        public function setParent(BaseCategory $parent = null)
        {
            $this->parent = $parent;
        }

        public function getParent()
        {
            return $this->parent;
        }
    }

Is it normal? How can I fix that?

Kevin
  • 4,823
  • 6
  • 36
  • 70
  • No. Circular dependencies are not normal. – Cerad Jul 28 '16 at 16:58
  • @Cerad... How Can we fix it? – Kevin Aug 01 '16 at 07:48
  • Not enough info to fix it. I'd suggest getting an out of the box example working then try adding in your entity. Usually these sorts of things pop up in doctrine entity listeners. The entity manager is dependent on each of it's listeners. If a listener in turn is dependent on the manager then you get a circular dependency. – Cerad Aug 01 '16 at 13:23

0 Answers0