Search code examples
phpsymfonyentity

“association refers to the inverse side field” & “mappings are inconsistent with self”


i have one entity and is relation with self. category is related by self and field name is parent. when load page Mapping errors show in profiler.

/**
 * Category
 *
 * @ORM\Table(name="category")
 * @ORM\Entity(repositoryClass="AdminBundle\Repository\CategoryRepository")
 * @UniqueEntity("urlcode")
 */
class Category
{
    /**
     * @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)
     */
    private $title;

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

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

    /**
     * @var int
     *
     * @ORM\Column(name="digiid", type="integer", unique=true)
     */
    private $digiid;

    /**
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="Category")
     * @ORM\JoinColumn(name="parent", referencedColumnName="id")
     */
    private $parent;

    

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

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

        return $this;
    }

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

    /**
     * Set urlcode
     *
     * @param string $urlcode
     *
     * @return Category
     */
    public function setUrlcode($urlcode)
    {
        $this->urlcode = $urlcode;

        return $this;
    }

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

    /**
     * Set image
     *
     * @param string $image
     *
     * @return Category
     */
    public function setImage($image)
    {
        $this->image = $image;

        return $this;
    }

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

    /**
     * Set digiid
     *
     * @param integer $digiid
     *
     * @return Category
     */
    public function setDigiid($digiid)
    {
        $this->digiid = $digiid;

        return $this;
    }

    /**
     * Get digiid
     *
     * @return integer
     */
    public function getDigiid()
    {
        return $this->digiid;
    }

    /**
     * Set parent
     *
     * @param \AdminBundle\Entity\Category $parent
     *
     * @return Category
     */
    public function setParent(\AdminBundle\Entity\Category $parent = null)
    {
        $this->parent = $parent;

        return $this;
    }

    /**
     * Get parent
     *
     * @return \AdminBundle\Entity\Category
     */
    public function getParent()
    {
        return $this->parent;
    }

    public function __toString()
    {
        return $this->title;
    }
}

profiler:

The association AdminBundle\Entity\Product#category refers to the inverse side field AdminBundle\Entity\Category#Category which does not exist.

The association AdminBundle\Entity\Product#brand refers to the inverse side field AdminBundle\Entity\Brand#Brand which does not exist.

The mappings AdminBundle\Entity\Product#link and AdminBundle\Entity\Link#product are inconsistent with each other.

The association AdminBundle\Entity\Category#parent refers to the inverse side field AdminBundle\Entity\Category#Category which does not exist.

The association AdminBundle\Entity\Category#category refers to the owning side field AdminBundle\Entity\Category#Category which does not exist.


Solution

  • Your issue is caused by inversedBy="Category". The error says, that there's no Category::$Category atribute, and indeed there isn't.

    inversedBy parameters is used to define the other side of relation in order to create bidirectional relationship.

    In your case it would be probably children, if you would want to have access from parent to its children categories.

    Since you don't have it, you cane simply remove this parameter. And it looks like you have this parameter used incorrectly also in other entities.

    If you want more information about how to define relationships in Doctrine ORM, take a look at documentation