Grails多列索引 [英] Grails multi column indexes

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

问题描述

有人可以解释如何在Grails中定义多列索引?文档最少是稀疏的。

Can someone explain how to define multi column indexes in Grails? The documentation is at best sparse.

这似乎不起作用:
http://grails.org/GORM+Index+definitions

我有一些运气与此,但结果似乎最好是随机的。在一个领域类中工作的定义不适用于另一个领域类(具有不同的课程名称)。
http://www.grails .org / doc / 1.1 / guide / single.html#5.5.2.6%20Database%20Indices

I've had some luck with this, but the results seems random at best. Definitions that works in one domain class does not when applied to another (with different names of course). http://www.grails.org/doc/1.1/guide/single.html#5.5.2.6%20Database%20Indices

一些工作示例和解释将非常感谢!

Some working examples and explanations would be highly appreciated!

推荐答案

对我来说多列索引的解决方案是:

The solution that has worked for me for multi-column indexes is:

class ClassName {
    String name
    String description
    String state

    static mapping = {
        name index: 'name_idx'
        description index: 'name_idx'
        state index: 'name_idx'
    }
}

这会在索引中创建一个名为'name_idx'的索引。

This creates an index called 'name_idx' with the three columns in the index.

下划线:列按字母顺序列在索引中,而不是按照他们输入的顺序列出。

Downside: the columns are listed in the index in alphabetical order, not the order that they were entered.

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

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