含まれているオブジェクトに基づいて派生プロパティを作成しようとしています。
以下の例:
class Generation {
String name
DateTime productionStart
DateTime productionEnd
static belongsTo = [line: Line]
static hasMany = [bodyStyles: BodyStyle, engines: Engine, models: Model]
static constraints = {
line nullable: false
name nullable: false, unique: ['line'], maxSize: 255, blank: false
}
static mapping = {
// I've tried but this solution causes errors
productionStart formula: 'MIN(engines.productionStart)'
// I've tried but this solution causes errors
productionEnd formula: 'MAX(engines.productionEnd)'
}
}
class Engine {
String name
Integer horsePower
DateTime productionStart
DateTime productionEnd
static belongsTo = [generation: Generation]
static hasMany = [models: Model]
static constraints = {
generation nullable: false
name nullable: false, unique: ['generation', 'horsePower'], maxSize: 255, blank: false
horsePower nullable: false
productionStart nullable: false
productionEnd nullable: true
}
static mapping = {
productionStart type: PersistentDateTime
productionEnd type: PersistentDateTime
}
}
Derived Properties Documentationを読みましたが、私の場合は、複雑なオブジェクトに関連付けられていない式よりも少し複雑です。
上記のコードで見つけることができる解決策は、エラーになります::
GrailsTagException が原因です: タグの実行中にエラーが発生しました: 行 [23] の式 [Generation.findAll()] を評価中にエラーが発生しました: クエリを実行できませんでした。SQL [this_.id を id22_0_、this_.version を version22_0_、this_.line_id を line3_22_0_、this_.name を name22_0_、MAX(engines.productionEnd) を formula0_0_、MIN(engines.productionStart) を formula1_0_ を生成 this_ から選択]; ネストされた例外は org.hibernate.exception.SQLGrammarException: クエリを実行できませんでした