且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 grails 域类中调整 Map 的约束/数据库映射

更新时间:2022-01-18 09:36:53

我成功使用的另一种方法是将地图推送到协作者域类的集合中.

An alternative approach I used successfully was to push the map out into a collection of a collaborator domain class.

class DynaProperty {
    String name
    String value

    static belongsTo = MyClass
    static constraints = {
        value(maxSize:4000)  //Or whatever number is appropriate
    }
}

然后在 MyClass 中:

And then in MyClass:

class MyClass {
    static hasMany = [dynaProperties:DynaProperty]
}

几乎是一张地图,它使您能够使用动态查找器来提取单个条目.

This is almost a map, and it gives you the ability to use dynamic finders to pull up an individual entry.