I have a self referencing entity with parent and children. The strange thing is, when I add the form elements (DoctrineModule ObjectSelect) for parent and children to the form, some other fields of the parent entity doesn't update, when I persist the entity. The child entities are updating fine.
In the update query of the parent aren't these fields which I want to update. It's like doctrine doesn't recognize the changes for the parent (owning side) anymore. Before the persist I get the right entity with the actual changes from the form, but than doctrine doesn't update the changed fields in the query.
When I delete the form elements for parent and children in the form, everything works fine and the parent entity update/persist all fields.
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(type="text")
*/
private $teaser;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(type="text")
*/
private $description;
/**
* One Category has Many Categories.
* @var Collection
* @ORM\OneToMany(targetEntity="Rental\Entity\Rental", mappedBy="parent")
*/
private $children;
/**
* Many Categories have One Category.
* @ORM\ManyToOne(targetEntity="Rental\Entity\Rental", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="houses_id", nullable=true, onDelete="SET NULL")
*/
private $parent;
public function __construct()
{
$this->children = new ArrayCollection();
}
/**
* Get teaser
*
* @return string
*/
public function getTeaser()
{
return $this->teaser;
}
/**
* Set teaser
*
* @param string $teaser
*/
public function setTeaser($teaser)
{
$this->teaser = $teaser;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set description
*
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Add $child
* @param Collection $children
*/
public function addChildren(Collection $children)
{
foreach ($children as $child) {
$this->addChild($child);
}
}
/**
* @param Rental $child
* @return void
*/
public function addChild(Rental $child)
{
if ($this->children->contains($child)) {
return;
}
$child->setParent($this);
$this->children[] = $child;
}
/**
* Remove children
* @param Rental $children
*/
public function removeChildren(Collection $children)
{
foreach ($children as $child) {
$this->removeChild($child);
}
}
/**
* Remove child.
*
* @param \Rental\Entity\Rental $child
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeChild(Rental $child)
{
return $this->children->removeElement($child);
}
/**
* Get children.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* Set parent.
*
* @param \Rental\Entity\Rental|null $parent
*/
public function setParent(Rental $parent = null)
{
$this->parent = $parent;
}
/**
* Get parent.
*
* @return \Rental\Entity\Rental|null
*/
public function getParent()
{
return $this->parent;
}