在 grails DOM 中指定 Map 集合的字段大小

发布于 2024-12-02 18:54:53 字数 1299 浏览 1 评论 0原文

我有一个 Grails 1.3.7 域类,其声明如下:

class Document {
    String url

    Map metadata = new HashMap()

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

生成的模式如下所示:

+-------------+--------------+------+-----+---------+----------------+
| 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    |       |
+--------------+--------------+------+-----+---------+-------+

我想知道如何为 document_metadata 表指定不同的类型(具体来说,不同的大小)。我希望能够存储长度超过 255 个字符的字符串。我在网上找不到任何相关文档,可能是因为我想不出任何好的关键字。地图和集合是非常通用的术语!

谢谢,

吉恩

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓬勃野心 2024-12-09 18:54:53

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

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.

不羁少年 2024-12-09 18:54:53

只需对数据库运行 sql alter 命令就非常容易了。这个 alter 命令的一个好地方是 BootStrap,并带有一些检查表列定义是否正常的逻辑。 Grails 不会触及已经创建的列。

It would be quite easy just to run an sql alter command to database. A good place for this alter command would be BootStrap and with some logic that checks the table column definitions wheter they're ok or not. Grails won't touch already created columns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文