1週間の検索と試行の後、私はここに来て問題を解決しなければなりません.
grails scaffoldingでモデル化する必要があるレガシー システムがあります。システムは、次の方法でレポート情報を収集します。
|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.インリスト
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']
}
}
または、カスタムバリデーターで可能な結果を制限することにより、部分的に足場を使用します。スキャフォールディングでは、回答の選択ボックスにすべてのオプションが表示されますが、独自のタイプの回答のみを保存できます。
2. カスタムバリデーター
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 |
最初のオプション (inList) は、スキャフォールディングを使用してこれを行う方法ですが、多くの作業が必要であり、これらの回答オプションがデータベースにないのは好きではありません。
2 番目の方法は有望に見えますが、たとえば answer1 が有効なオプション ('A'、'B'、'C') のみを scaffold ドロップボックスに出力するように、scaffolding によって出力される出力された回答を制限する方法はわかりません。
足場でこれを行うより良い方法を知っている人はいますか?