But I have the same bug in my project. #1971 #1663 #2004
OneToMany doesn't save.
I have Article Entity
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
*/
class Article
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Dossier", inversedBy="articles", cascade={"persist","remove"})
*/
private $dossier;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return mixed
*/
public function getDossier()
{
return $this->dossier;
}
/**
* @param mixed $dossier
*/
public function setDossier($dossier)
{
$this->dossier = $dossier;
return $this;
}
public function __toString()
{
return $this->getName();
}
}
And this entity
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\DossierRepository")
*/
class Dossier
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="dossier", cascade={"persist","remove"})
*/
private $articles;
public function __construct() {
$this->articles = new ArrayCollection();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
public function __toString()
{
return $this->getName();
}
/**
* @return mixed
*/
public function getArticles()
{
return $this->articles;
}
public function addArticle(Article $article) {
$article->setDossier($this);
$this->articles->add($article);
return $this;
}
public function removeArticle(Article $article) {
$article->setDossier(null);
$this->articles->removeElement($article);
return $this;
}
}
My EasyAdmin config it's really easy
easy_admin:
entities:
# List the entity class name you want to manage
Article:
class: App\Entity\Article
Dossier:
class: App\Entity\Dossier
form:
fields:
- 'name'
- { property: 'articles', type_options: { by_reference: false } }
But when I save in page Dossier, I have every time Article empty.
Any idea ?
For fix I need to overload EntityController and function preUpdateEntity and use my function addArticle for all getArticles.
It's possible without this trick ?
I have the same problem. In issue #1918 says that it works, but not for me.
I found a solution to remove, but nor for update
Change:
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="dossier", cascade="persist","remove"})
*/
in Dossier.php to:
/**
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="dossier", cascade={"persist","remove"}, orphanRemoval=true)
*/
And change:
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Dossier", inversedBy="articles", cascade={"persist","remove"})
*/
in Article.php to
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Dossier", inversedBy="articles")
*/
This is a special kind of magic...
I've the same problem since 1.17.8 > updates in children are not saved.
If I force 1.17.7 in composer, still ok.
@javiereguiluz
I guess problem is here https://github.com/javiereguiluz/EasyAdminBundle/commit/6a365fcc13226eb52139ab0d324fc1369cc2430d
@grachevko I don't understand why that could be the problem :(
@javiereguiluz flush with $entity argument perisist only this entity without relations.
It's ok with the master branch thank @grachevko I wait the new release :)
@javiereguiluz the problem is explained in the following thread: https://github.com/doctrine/doctrine2/issues/4142
@javiereguiluz can confirm that flush with $entity arg persists $entity without relations.
@grachevko thank you, i've updated my project, it's now working.
I'm closing this issue because we're starting a new phase in the history of this bundle (see #2059). We've moved it into a new GitHub organization and we need to start from scratch: no past issues, no pending pull requests, etc.
I understand if you are angry or disappointed by this, but we really need to "reset" everything in order to reignite the development of this bundle.
Just try to disable by reference on your field https://symfony.com/doc/current/reference/forms/types/choice.html#by-reference
Most helpful comment
I guess problem is here https://github.com/javiereguiluz/EasyAdminBundle/commit/6a365fcc13226eb52139ab0d324fc1369cc2430d