gpt4 book ai didi

php - 缺少主键 id 的值 Doctrine Symfony2

转载 作者:可可西里 更新时间:2023-11-01 07:30:18 25 4
gpt4 key购买 nike

我正在研究 symphony 2.8.2 学说中两个实体之间的连接。我不断收到“主键 ID 缺失值”

这是缺少 ID 的 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 名称的错误。

将您的映射更改为:

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

注意:这是默认配置,也可以删除该行,因为它没有用。

编辑

我是对的,但没有指出真正的问题。
您收到此错误是因为您尝试使用不是主键的列作为 joinColumn

referencedColumnName

以下内容:

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

应该是:

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

来自 this similar questionthe owner's answer (与完全相同的错误相关):

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?

关于php - 缺少主键 id 的值 Doctrine Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35581176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com