Class Carro {
String name
String marca
String matricula
}
Class CarroMovel{
String pro1
String prop2
String prop3
Carro carro
static hasMany = [ carros: Carro]
}
def save2 = {
def carroInstance = new Carro()
def carroMovelInstance = new CarroMovel()
carroInstance.name = params.name
carroInstance.marca = params.marca
carroInstance.matricula = params.matricula
carroMovelInstance.prop1 = params.carroMovel.prop1
carroMovelInstance.prop2 = params.carroMovel.prop2
carroMovelInstance.prop3 = params.carroMovel.prop3
carroInstance.save()
carroMovelInstance.carro = carroInstance
carroMovelInstance.save()
}
CarroInstance正在保存,但carroMovelInstance不是。我想不明白。任何帮助都会被贬低。
答案 0 :(得分:1)
您可能遇到验证错误。尝试在其上调用validate()
并检查错误。或者,尝试使用carroMovelInstance.save(failOnError: true)
保存它,如果它不验证,您将收到异常。