Doctrine 2 with multiple indexes(具有多个索引的 Doctrine 2)
问题描述
我正在使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有多个索引的 Doctrine 2


基础教程推荐
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01