2016-02-12 82 views
0
games = Game.where { 
    categories.categoryName == currentCategory 
    platform.platformName == chosenPlatform 
    status == "okay" 
}.list(sort: 'gameTitle', order: "asc", max: max, offset: offset) 

所以在这里我选它的名字游戏,问题是大写字母至上所以三角洲来自布拉沃这应该是反过来了。你如何在Grails中做到这一点?Grails的排序忽略大小写敏感

回答

1

这是纯粹的数据库 - Grails/Gorm/Hibernate生成一个查询,将它发送到您的数据库并处理结果 - 就是这样。如果你的数据库种类的区分大小写的,那么你有两种选择:

  • 设置列(或整个数据库如果可能的话)是不区分大小写。
  • 使用的功能(如UPPERLOWER)的ORDER BY子句中(如ORDER BY UPPER(game_title)

更多见http://grails.github.io/grails-doc/latest/guide/GORM.html#5.5.2.11%20Derived%20Properties的公式字段。

+0

嗨,我不能在Grails文档中看到ORDER BY,你如何实现它?我做,列表(排序:ORDER BY UPPER(game_title),order:“asc”,max:max,offset:offset)? –

2

你必须使用派生属性

class Game { 
    String title 

    static mapping = { 
     titleUpper formula: 'UPPER(title)' 
    } 
} 

而你的清单

games = Game.where { 
    categories.categoryName == currentCategory 
    platform.platformName == chosenPlatform 
    status == "okay" 
}.list(sort: 'titleUpper', order: "asc", max: max, offset: offset)