简体   繁体   English

Doctrine2关系-如何设置不存在的关联实体对象

[英]Doctrine2 relations - how to set inexistant associate entity object

I have 2 entities: SectionAdmin and Section. 我有2个实体:SectionAdmin和Section。

The relation is ManyToOne from SectionAdmin to Section. 从SectionAdmin到Section的关系是ManyToOne。

Now, in the MySQL table, I can add section_id to be 0, that means that the SectionAdmin will be admin of all the sections, but Doctrine is not allowing me to do that. 现在,在MySQL表中,我可以将section_id添加为0,这意味着SectionAdmin将成为所有节的管理员,但是Doctrine不允许我这样做。

I need to specify a valid Section object. 我需要指定一个有效的Section对象。

Any idea on how to do that? 关于如何做到这一点的任何想法?

I did this in an easier way: 我以一种更简单的方式做到了这一点:

$insertEditorRightSQL = "INSERT INTO section_admin(section_id) VALUES (0) ";

$insertEditorRight = $em->getConnection()->prepare($insertEditorRightSQL); 
$insertEditorRight->execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM