In my admin I have a OneToMany defined as it:
/**
* @ORM\OneToMany(targetEntity="Module", mappedBy="sequence", cascade={"persist", "remove"})
*/
private $modules;
And the inversed side:
/**
* @ORM\ManyToOne(targetEntity="ModuleSequence", inversedBy="modules", cascade={"persist"}, fetch="LAZY")
* @ORM\JoinColumn(name="sequence_id", referencedColumnName="id")
*/
protected $sequence;
In my admin class I defined the 'modules' field as it:
->add('modules', 'sonata_type_collection',array(
'by_reference' => false
))
Finally in the ModuleSequence Entity here's the addModule method:
/**
* Add modules
*
* @param \AppBundle\Entity\Module $module
* @return ModuleSequence
*/
public function addModule(\AppBundle\Entity\Module $module)
{
$module->setSequence($this);
$this->modules[] = $module;
return $this;
}
I have the "add" button, I get the modal, I fill it and validate. The Ajax request is sent into the profiler but no new row appear.
The 'sequence_id' is not set in the database and I don't know why... Any idea please?
When I use the 'inline' & 'table' options, the id is well set.
After a long discussion on Sonata Admin GitHub here:
https://github.com/sonata-project/SonataAdminBundle/issues/4236
Problem partially solved...