I\'m trying to create derived properties based on contained objects.
Example below:
class Generation {
String name
DateTime productionStart
Another way to try it is to create a getter instead of derived properties:
class Generation {
String name
DateTime productionStart
DateTime productionEnd
static transients = ['productionStart','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
}
DateTime getProductionStart() {
def datetime = Engine.createCriteria().get {
eq('generation',this)
projections {
min('productionStart')
}
}
return datetime
}
DateTime getProductionEnd() {
def datetime = Engine.createCriteria().get {
eq('generation',this)
projections {
max('productionEnd')
}
}
return datetime
}
}