問題描述
我正在使用 Zend 框架和 Doctic2.1 進行開發.
I am developing using zend framework and doctrine2.1.
我從數據庫生成了實體.
I have generated entities from database.
但問題是:Doctrine 無法識別我的索引.它們根本沒有在實體注釋中標記.
But the problem is: Doctrine doesn't recognize my indexes. They are not marked in entity annotations at all.
當我去驗證模式并從 orm:schema-tool:update --dump-sql
轉儲 sql 時,它會生成 sql 來刪除整個數據庫中的所有索引.
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.
我發現 Doctrine 有以下用于定義索引的注釋:
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.
推薦答案
我會說你可以在 indexs 屬性中插入多個索引(但我沒有時間測試它):
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"})
}
希望對你有幫助
這篇關于具有多個索引的 Doctrine 2的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!