У меня есть самоссылающийся объект с родителем и детьми. Странно то, что когда я добавляю элементы формы (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;
}
cascade={"persist"}
(чтобы разрешить удаление, также добавьте,"remove"
в похвалах). - person rkeet   schedule 02.05.2018isValid()
, прочитайте это. Затем убедитесь, что до проверки вы выполняете:$form->bind(new Entity())
и$form->setData($this->getRequest()->getData())
. Затем после проверки выполните:$entity = $form->getObject(); $this->getObjectManager()->persist($entity); $this->getObjectManager()->flush($entity);
. ... Ок, напишу в маленьком ответе. - person rkeet   schedule 04.05.2018