简体   繁体   English

具有多个索引的 Doctrine 2

[英]Doctrine 2 with multiple indexes

I am developing using zend framework and doctrine2.1.我正在使用 Zend 框架和 Doctic2.1 进行开发。

I have generated entities from database.我从数据库生成了实体。

But the problem is: Doctrine doesn't recognize my indexes.但问题是:Doctrine 无法识别我的索引。 They are not marked in entity annotations at all.它们根本没有在实体注释中标记。

And when I go to validate-schema and dump sql from orm:schema-tool:update --dump-sql it generates sql to drop all my indexes across whole database.当我去验证模式并从orm:schema-tool:update --dump-sql转储 sql 时,它会生成 sql 以删除整个数据库中的所有索引。

I found that Doctrine has following annotation used for defining indexes:我发现 Doctrine 有以下用于定义索引的注释:

indexes={@index(name="index_name",
                columns={"database_column1","database_column2"}
        )}

But this allows me to define one index for multiple columns and I don't really need that.但这允许我为多列定义一个索引,而我并不真正需要它。
What I want is the ability to define multiple indexes on multiple columns, one index per column.我想要的是能够在多列上定义多个索引,每列一个索引。

Is there a way I can achieve this?有没有办法实现这一目标? Is there a way that I can have annotation that defines multiple indexes.有没有办法让我可以有定义多个索引的注释。

I would say you can insert multiple indexes in the indexes property (but I haven't had the time to test it):我会说你可以在索引属性中插入多个索引(但我没有时间测试它):

indexes={
@ORM\Index(name="index_name", columns={"database_column1","database_column2"}),
@ORM\Index(name="index_name2", columns={"database_column1"}),
@ORM\Index(name="index_name3", columns={"database_column2"})
}

Hope this helps you希望这对你有帮助

Here is an example:下面是一个例子:

/**
 * @Entity
 * @Table(name="serial_number",indexes={
 *  @index(name="product_idx", columns={"product_id"}),
 * })
 */
class SerialNumber { // Entity Class

    /**
     * @var int
     * 
     * @Id
     * @GeneratedValue
     * @Column(type="integer")
     */

    protected $id;

    /**
     * @Column(name="created_at", type="datetime")
     * @var \DateTime
     * */
    protected $created;

    /**
     * @Column(name="updated_at", type="datetime")
     * @var \DateTime
     * */
    protected $updated;

    /**
     * @Column(name="product_id", type="integer")
     */
    protected $productID;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM