Ste
Ste

Reputation: 685

Doctrine self join entity

I'm having trouble self joining an entity on oneToMany. My entity looks like:

/*
 * @ORM\ManyToOne(targetEntity="IntegritBundle\Entity\UserMessage", inversedBy="related", cascade={"persist", "remove"})
 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
 * @Serial\Expose
 * @Serial\Groups({"all", "basic"})
 */
public $parent;

/**
 * @var ArrayCollection
 * @ORM\OneToMany(targetEntity="IntegritBundle\Entity\UserMessage", mappedBy="parent", cascade={"persist", "remove"})
 * @Serial\Expose
 * @Serial\Groups({"all", "basic"})
 */
public $related;

But when querying it I get the error Notice: Undefined index: parent `

It’s the mappedBy in the $related property that’s causing the problem but I don’t see why

Upvotes: 0

Views: 163

Answers (1)

Ste
Ste

Reputation: 685

The problem was a missing * on the docblock for $parent :)

Upvotes: 1

Related Questions