【问题标题】:Grails change database column size of a hasMany of StringsGrails 更改 hasMany of Strings 的数据库列大小
【发布时间】:2014-07-05 18:33:21
【问题描述】:

我有一个如下所示的域类:

class Foo {
    static hasMany = [bar: String]
}

问题是这会在 MySQL 中创建一个包含 VARCHAR(255) 列的连接表,它比我需要的要大得多。在我的示例中, bar 是 Set 而不是索引集合,因此尝试使用 indexColumn 不起作用。 joinTable 没有更改列类型/长度的属性。是否可以在不更改域类结构的情况下更改列大小?

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    这有效(用 grails 2.4 测试):

    class Foo {
        static hasMany = [
            bars:String
        ]
    
        static mapping = {
            bars joinTable: [column: 'BARS_STRING', length: 112]
        }
    }
    

    【讨论】:

      【解决方案2】:

      你也可以试试sqlType,点赞

      class Foo {
          static hasMany = [bar: String]
      
          static mapping = {
              names joinTable: [column: 'bar', sqlType: 'varchar(32)']
          }
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-23
        • 2016-04-15
        • 1970-01-01
        • 2022-12-02
        • 1970-01-01
        • 2014-11-02
        相关资源
        最近更新 更多