简体   繁体   English

如何在symfony2中添加不在数据库中的子文件

[英]How to add a child filed that is not in db in symfony2

I have a school table.我有一张school桌子。 which contains a parent_school_id for parent school.其中包含父学校的parent_school_id

But in form I need to add two filed 1) for parent school 2) for child school.但在表格中,我需要添加两个提交的 1) 为家长学校 2) 为子学校。

for parent school it work in entity by following code of entity :对于家长学校,它通过以下实体代码在实体中工作:

/**
 * @ORM\Column(name="parent_school_id",type="integer", nullable=true)
 * @ORM\OneToOne(targetEntity="School", mappedBy="id")
 */
protected $parentSchool;

now I add a child school but it is not in db so i added follow code :现在我添加了一所儿童学校,但它不在数据库中,所以我添加了以下代码:

/**
 * @OneToOne(targetEntity="School")
 * @JoinColumn(name="child_school_id", referencedColumnName="id")
 */
protected $childSchool;

it give me following error ::它给了我以下错误::

[Semantical Error] The annotation "@OneToOne" in property Epx\Bundle\CourseBundle\Entity\School::$childSchool was never imported. Did you maybe forget to add a "use" statement for this annotation? 

How can I add this extra filed without db field ?如何在没有 db 字段的情况下添加这个额外的文件?

It works when I put this code :当我放置此代码时它有效:

/**
 * @ORM\OneToOne(targetEntity="School", mappedBy="parentSchool")
 */
protected $childSchool;
/**
 * @ORM\ManyToOne(targetEntity="School", inversedBy="childSchool")
 * @ORM\JoinColumn(name="parent_school_id", referencedColumnName="id")
 */
protected $parentSchool;

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

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