在我的管理中,定义了一个OneToMany:
/**
* @ORM\OneToMany(targetEntity="Module", mappedBy="sequence", cascade={"persist", "remove"})
*/
private $modules;而倒转的一面:
/**
* @ORM\ManyToOne(targetEntity="ModuleSequence", inversedBy="modules", cascade={"persist"}, fetch="LAZY")
* @ORM\JoinColumn(name="sequence_id", referencedColumnName="id")
*/
protected $sequence;在我的管理类中,我将“模块”字段定义为:
->add('modules', 'sonata_type_collection',array(
'by_reference' => false
))最后,在ModuleSequence实体中,下面是addModule方法:
/**
* Add modules
*
* @param \AppBundle\Entity\Module $module
* @return ModuleSequence
*/
public function addModule(\AppBundle\Entity\Module $module)
{
$module->setSequence($this);
$this->modules[] = $module;
return $this;
}我有“添加”按钮,我得到了模态,我填充它并验证。Ajax请求被发送到分析器中,但没有出现新的行。
数据库中没有设置“sequence_id”,我不知道为什么.有什么想法吗?
当我使用“内联”和“表”选项时,id是很好设置的。
发布于 2016-12-16 21:40:03
在对奏鸣曲管理GitHub进行了长时间的讨论之后,在这里:
https://github.com/sonata-project/SonataAdminBundle/issues/4236
问题部分解决了..。
发布于 2016-12-03 19:35:03
有相同的问题,并通过重写prePersist和preUpdate方法来解决它,然后持久化这些关联。
public function prePersist($object)
{
$this->persistBlocks($object);
$content->mergeNewTranslations();
}
public function preUpdate($object)
{
$this->prePersist($object);
}
private function persistModules($object)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager');
foreach($object->getModules() as $module)
{
$module->setObject($object); // change Object to the name of your Entity!!
$em->persist($module);
}
}https://stackoverflow.com/questions/40941466
复制相似问题