Reputation: 448
I have 4 classes where the parent is relationated with other classes, but child does not set the relation and the validate() say me that the property can't be null but i really set that!
class Lote {
static hasMany = [movimientos:Movimiento]
}
class Almacen {
static hasMany = [entradas:Movimiento]
}
class Movimiento {
static belongsTo = [lote:Lote, destino:Almacen]
}
class Ingreso extends Movimiento{
def Almacen getDestino(){
return this.destino
}
def Almacen getOrigen(){
return null
}
}
And my MovimientoService does:
def registrarIngreso(def loteId, def params){
Movimiento ingreso = new Ingreso(params)
ingreso.lote = Lote.get(loteId)
ingreso.destino = Almacen.get(params.almacenId)
if (ingreso.validate()){
ingreso.save flush:true
}
return ingreso
}
Movimiento need to be a abstract class, i know.
The almace.lote is setted, but the almace.destino don't.
Why? I forgot something? The Lote and Movimiento classes have the same relation of Almacen and Movimiento.
Upvotes: 0
Views: 74
Reputation: 1120
I think setting def Almacen getDestino()
in Ingreso
class may be a problem - can you try removing this method?
You don't have to manually create a getter anyway, GORM should figure out that it should return the destino
object.
Upvotes: 1