[英]Symfony2 mapping works for one entity but not the other
I have two Entitites mapped together. 我有两个实体映射在一起。
Skin.php : Skin.php:
/**
* @var CmsElement
*
* @ORM\ManyToOne(targetEntity="CmsElement")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="homepage_id", referencedColumnName="id")
* })
*/
private $homepage;
CmsElement.php : CmsElement.php:
/**
* @var Skin
*
* @ORM\ManyToOne(targetEntity="Skin")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="skin_id", referencedColumnName="id")
* })
*/
private $skinId;
And thats it. 就是这样。 My Skin table is mapped correctly, I get the id of the CmsElement.
我的皮肤表已正确映射,我得到了CmsElement的ID。 However in my Cmselement I dont get the needed skinId... It always stays NULL.
但是在我的Cmselement中,我没有获得所需的skinId ...它始终保持为NULL。 The codes are identical, why doesnt it work?
密码是相同的,为什么不起作用?
An example for better understanding: 一个更好理解的示例:
Skin: 皮肤:
id: 1
homepage_id: 2
CmsElement: CmsElement:
id: 2
skin_id: NULL
In order to set ManyToOne relation, you have to specify it in both ways like this: 为了设置ManyToOne关系,您必须以两种方式指定它:
// Skin.php
/**
* @var CmsElement
*
* @ORM\OneToMany(targetEntity="CmsElement", mappedBy="skinId")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="homepage_id", referencedColumnName="id")
* })
*/
private $homepage;
// CmsElement.php :
/**
* @var Skin
*
* @ORM\ManyToOne(targetEntity="Skin", inversedBy="homepage")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="skin_id", referencedColumnName="id")
* })
*/
private $skinId;
But, please take care of this points: 但是,请注意以下几点:
Here you can find informations in order to do your relation in the right way: Sf2 Doc 在这里,您可以找到信息,以便以正确的方式进行联系: Sf2文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.