我有一个带有父母和孩子的自引用实体。奇怪的是,当我将父级和子级的表单元素(DoctrineModule ObjectSelect)添加到表单时,当我持久化实体时,父实体的其他一些字段不会更新。子实体更新正常。
在父级的更新查询中,这些字段不是我要更新的。就像学说不再承认父母(拥有方)的变化一样。在持久化之前,我从表单中获得了具有实际更改的正确实体,但学说不会更新查询中更改的字段。
当我删除表单中父项和子项的表单元素时,一切正常,父实体更新/保留所有字段。
/**
* @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;
}