如何使用grails脚手架为遗留表建模

如何使用grails脚手架为遗留表建模,grails,gorm,Grails,Gorm,经过一周的搜索和尝试,我不得不带着我的问题来到这里 我有一个遗留系统,需要使用grails脚手架进行建模。系统通过以下方式收集报告信息: |customer_id|Question_1 |Question_2|...|Question_N| |123 |A |Z |...|D | |456 |B |X |...|E | 其中问题的答案集为: Question 1

经过一周的搜索和尝试,我不得不带着我的问题来到这里

我有一个遗留系统,需要使用grails脚手架进行建模。系统通过以下方式收集报告信息:

|customer_id|Question_1  |Question_2|...|Question_N|
|123        |A           |Z         |...|D         |
|456        |B           |X         |...|E         |
其中问题的答案集为:

Question 1: A,B,C
Question 2: Z,X,Y
Question N: D,E,F
在很多这样的表中,N超过100。

我知道我可以用以下方式对表建模(不介意语法)

1.内列表 或者通过限制自定义验证器的可能结果来部分使用脚手架。脚手架在答案的选择框中显示所有选项,但只允许保存自己类型的答案:

2.自定义验证器 后一个例子中的问题表 第一个选项(inList)是一种使用脚手架的方法,但它需要大量的工作,我不喜欢这些答案选项不在数据库中

第二种方法看起来很有希望,但我不知道如何限制脚手架打印的答案,例如answer1将只打印有效选项('A','B','C')到脚手架dropbox


是否有人知道使用脚手架进行此操作的更好方法?

您似乎可以动态更改约束,请参见此处:
class InformationTable {
    Int customerId
    String question1
    String question2
    .
    .
    String questionN

    static constraints = {
        question1 inList: ['A','B','C']
        question2 inList: ['Z','X','Y']
        .
        .
        questionN inList: ['D','E','F']
    }
}
class InformationTable {
    Int customerId
    Answer answer1
    Answer answer2
    .
    .
    answer answerN

    // again, don't mind about the syntax 
    // I wrote this out of memory and will 
    // check the syntax in the evening

    static constraints = {
        answer1 validator: { val, obj ->
            obj.answer1.type == 'question1'
        }
        answer2 validator: { val, obj ->  
            obj.answer2.type == 'question2'
        }   
        .
        .
        answerN validator: { val, obj ->  
            obj.answerN.type == 'questionN'
        }
    }
}

class Answer {
    String name
    String type
}
|type     |name|
|question1|A   |
|question1|B   |
|question1|C   |
|question2|Z   |
|question2|X   |
|question2|Y   |
|question3|D   |
|question3|E   |
|question3|F   |