[英]Simple index definition in Doctrine 2
Is there a simple way to define a non-unique index over a column? 有没有一种简单的方法来定义列上的非唯一索引?
When I define unique index, this is perfectly sufficient: 当我定义唯一索引时,这是完全足够的:
/** @ORM\Entity */
class Foo {
/** @ORM\Column(type="string", unique=true) */
private $foo;
}
However, for non-unique index, I need this bunch of boilerplate: 但是,对于非唯一索引,我需要这一堆样板:
/**
* @ORM\Entity
* @ORM\Table(indexes={@Index(name="foo_idx", columns={"foo"})})
*/
class Foo
{
/** @ORM\Column(type="string") */
private $foo;
}
I'd prefer something like @ORM\\Index
annotation on the single property, or index=true
etc... 我更喜欢
@ORM\\Index
annotation在单个属性上,或者index=true
等...
I have to disappoint you... 我不得不让你失望......
@ORM\Table(indexes={@Index(name="foo_idx", columns={"foo"})})
is as simple as the annotation can get. 就像注释一样简单。
If $foo
would be a relating entity it would be indexed automatically, but for indexing fields you need to add the index as you did. 如果
$foo
是一个相关实体,它将被自动编入索引,但对于索引字段,您需要像您一样添加索引。
You can find all @Column
attributes here in the Doctrine 2 documentation . 您可以在Doctrine 2文档中找到所有
@Column
属性。 Sadly enough index
is not among them. 可悲的是,
index
不在其中。
Maybe you can make a feature request here on GitHub . 也许你可以在GitHub上提出功能请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.