【问题标题】:Simple index definition in Doctrine 2教义 2 中的简单索引定义
【发布时间】:2017-05-06 23:41:53
【问题描述】:

是否有一种简单的方法来定义列上的非唯一索引?

当我定义唯一索引时,这就足够了:

/** @ORM\Entity */
class Foo {
    /** @ORM\Column(type="string", unique=true) */
    private $foo;
}

但是,对于非唯一索引,我需要这一堆样板:

/**
 * @ORM\Entity
 * @ORM\Table(indexes={@Index(name="foo_idx", columns={"foo"})})
 */
class Foo
{
    /** @ORM\Column(type="string") */
    private $foo;
}

我更喜欢 @ORM\Index 在单个属性上的注释,或者 index=true 等...

【问题讨论】:

    标签: php indexing doctrine-orm annotations


    【解决方案1】:

    我不得不让你失望......

    @ORM\Table(indexes={@Index(name="foo_idx", columns={"foo"})})
    

    和注解一样简单。

    如果$foo 是一个相关实体,它将被自动编入索引,但对于索引字段,您需要像以前一样添加索引。

    您可以找到所有@Column 属性here in the Doctrine 2 documentation。很遗憾index 不在其中。

    也许您可以提出功能请求here on GitHub

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 2012-01-17
      • 2020-07-10
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多