【发布时间】:2015-04-16 04:55:20
【问题描述】:
我有一个场景,我需要使用 Doctrine 的 MappedSuperclass 功能(使用 Symfony2),并在某些超类列上创建唯一约束。比方说:
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'.
有没有办法定义映射超类的唯一约束?
【问题讨论】:
-
试试
some_column,因为学说将camelCase转换为underscore_case -
@kmlnvm 不起作用 - 同样的错误。
-
我刚刚用 camelCase 测试了它,它可以工作,我不明白你为什么会出错
-
生成实体,可能是没有getter/setter造成的
-
@krojew 尝试使用
protected而不是private作为实体字段。对于实体字段,您应该始终使用protected或public。
标签: php symfony doctrine-orm