gpt4 book ai didi

php - Doctrine MappedSuperclass 和唯一约束

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:24 26 4
gpt4 key购买 nike

我有一个场景,我需要使用 Doctrine 的 MappedSuperclass 功能(使用 Symfony2),并在一些父类(super class)列上创建一个唯一约束。比方说:

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\MappedSuperclass
*/
class Base
{
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $someColumn;
}

/**
* @ORM\Entity
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="column_idx", columns={"someColumn"})})
*/
class Concrete extends Base
{
}

问题出在模式生成期间@ORM\Table 注释的处理:

[Doctrine\DBAL\Schema\SchemaException]                          
There is no column with name 'someColumn' on table 'Concrete'.

有没有办法定义映射父类(super class)的唯一约束?

最佳答案

由于答案作者没有自己贴出答案,所以我引用他的话:

Try to use protected instead of private for entity field. You should always use protected or public for entity fields

关于php - Doctrine MappedSuperclass 和唯一约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28528571/

26 4 0
文章推荐: javascript - 制作具有链接行为的 html 按钮的最佳方法是什么?
文章推荐: ios - 如何在 Swift 4 中使用#keyPath()?
文章推荐: html - 在