在grails DOM中指定Map集合的字段大小 [英] Specifying field size of Map collection in grails DOM

查看:97
本文介绍了在grails DOM中指定Map集合的字段大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class Document {
字符串网址

映射元数据=新的HashMap()

静态约束= {
url(可为空,false,空:false,maxSize:2048)
元数据()
}
}

生成的模式如下所示:

  + ------------- + ---------- ---- + ------ + ----- + --------- + ---------------- + 
|字段|类型|空| Key |默认|额外|
+ ------------- + -------------- + ------ + ----- + --- ------ + ---------------- +
| id | bigint(20)| NO | PRI | NULL | auto_increment |
| url | longtext | NO | | NULL | |
+ ------------- + -------------- + ------ + ----- + --- ------ + ---------------- +

+ -------------- + - ------------ + ------ + ----- + --------- + ------- +
|字段|类型|空| Key |默认|额外|
+ -------------- + -------------- + ------ + ----- + - ------- + ------- +
|元数据| bigint(20)|是| | NULL | |
| metadata_idx | varchar(255)|是| | NULL | |
| metadata_elt | varchar(255)| NO | | NULL | |
+ -------------- + -------------- + ------ + ----- + - ------- + ------- +

我在想我可以为document_metadata表指定不同的类型(特别是不同的大小)。我希望能够存储超过255个字符的字符串。我在网上找不到任何相关文档,可能是因为我无法提出任何好的关键字。

谢谢,

基因

解决方案

你要能够影响你的元数据的DDL的唯一方法是使其成为一个具体的域类。使用HashMap不会给你这样做的能力。


I have a Grails 1.3.7 domain class that is declared like this:

class Document {
    String url

    Map metadata = new HashMap()

    static constraints = {
        url(nullable:false, blank: false, maxSize: 2048)
        metadata()
    }
}

The schema that is generated looks like this:

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| url         | longtext     | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| metadata     | bigint(20)   | YES  |     | NULL    |       |
| metadata_idx | varchar(255) | YES  |     | NULL    |       |
| metadata_elt | varchar(255) | NO   |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+

I am wondering how I can specify different types (specifically, different size) for the document_metadata table. I would like to be able to store strings longer than 255 characters. I could not find any relevant documentation online, possibly because I couldn't come up with any good keywords. Map and Collection are pretty generic terms!

Thanks,

Gene

解决方案

The only way you are going to be able to influence the DDL for your "metadata" is to make it a concrete domain class. Using HashMap isn't going to give you the ability to do so.

这篇关于在grails DOM中指定Map集合的字段大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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