How to adjust constraints / DB mapping for Map within grails domain class

前端 未结 2 1427
生来不讨喜
生来不讨喜 2020-12-11 07:05

Following grails domain class:

class MyClass {
  Map myMap
}

Now for myMap, grails automatically creates a new table for the elements in th

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 07:24

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

    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.

提交回复
热议问题