简体   繁体   中英

Grails 2.5 don't save an assignment of parent's property class in child class

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM