主键ID Doctrine Symfony2缺少值 [英] Missing value for primary key id Doctrine Symfony2

查看:79
本文介绍了主键ID Doctrine Symfony2缺少值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究两个交响曲2.8.2中的实体之间的连接。我不断收到主键ID的缺失值

I'm working on a join between two entities in doctrine on symphony 2.8.2. I keep getting "Missing value for primary key id"

此处为缺少的ID的ID注释。

Heres the id annotation for the missing id.

 /**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

这是我的联接:

/**
 * @ORM\OneToOne(targetEntity="FYP\BaseDesignBundle\Entity\SessionDesign", inversedBy="user")
 * @ORM\JoinColumn(name="fcid", referencedColumnName="id")
 */
private $sessionDesign;


/**
 * @ORM\OneToOne(targetEntity="FYP\UserBundle\Entity\User", inversedBy="sessionDesign")
 * @ORM\JoinColumn(name="id", referencedColumnName="fcid")
 */
private $user;


推荐答案

这是来自 joinColumn 您的关联名称。

It's a mistake coming from the joinColumn name of your association.

将映射更改为:

/**
 * @ORM\OneToOne(targetEntity="FYP\UserBundle\Entity\User", inversedBy="sessionDesign")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
private $user;

注意:这是默认配置,由于该行无用,因此也可以删除该行。

Note: That is the default configuration, also the line can be removed because it's useless.

编辑

我是对的,没有指出真正的问题。

之所以出现此错误,是因为您尝试使用不是主键的列作为 joinColumn referencedColumnName c>

I was right without pointing the real problem.
You are getting this error because you are trying to use a column that is not a primary key as the referencedColumnName of your joinColumn

以下内容:

* @ORM\JoinColumn(name="id", referencedColumnName="fcid")

应为:

* @ORM\JoinColumn(name="user_id", referencedColumnName="id")

来自与此类似问题所有者的答案(与完全相同的错误有关):

From this similar question at the owner's answer (related to the exactly same error):


我们不可能e联接指向非主键的列。 Doctrine会认为这些是主键,并使用数据创建延迟加载代理,这可能导致意外结果。由于性能原因,Doctrine不能在运行时验证此设置的正确性,而只能通过验证模式命令来验证。

It is not possible to use join columns pointing to non-primary keys. Doctrine will think these are the primary keys and create lazy-loading proxies with the data, which can lead to unexpected results. Doctrine can for performance reasons not validate the correctness of this settings at runtime but only through the Validate Schema command.

类似问题

Similar question Is it possible to reference a column other than 'id' for a JoinColumn?

这篇关于主键ID Doctrine Symfony2缺少值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆