具有多个索引的原则2 [英] Doctrine 2 with multiple indexes

查看:140
本文介绍了具有多个索引的原则2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用zend框架和doctrine2.1。



我已经从数据库生成了实体。



但问题是:Doctrine不能识别我的索引。在实体注释中没有标记它们。



当我从 orm:schema-tool:update转到validate-schema并转储sql时--dump-sql 它生成sql以将整个数据库中的所有索引全部删除。



我发现Doctrine有以下注释用于定义索引:

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

但是这可以让我为多个列定义一个索引,不需要。

我想要的是能够在多个列上定义多个索引,每列一个索引。



是否有一个可以实现这个的方法?有没有办法可以有多个索引的注释。

解决方案

我会说你可以在索引中插入多个索引财产(但没有时间测试):

  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})
}

希望这有助于您


I am developing using zend framework and doctrine2.1.

I have generated entities from database.

But the problem is: Doctrine doesn't recognize my indexes. 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.

I found that Doctrine has following annotation used for defining indexes:

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 didn'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

这篇关于具有多个索引的原则2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆