Grails多个数据绑定域类 [英] Grails multiple databinding domain classes

查看:144
本文介绍了Grails多个数据绑定域类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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不是。我无法想像出来任何帮助将被解除。

The CarroInstance is saving, but the carroMovelInstance isn't. I cannot figure it out. Any help would be apreciated.

推荐答案

您可能有验证错误。尝试调用 validate()并检查错误。或者,尝试使用 carroMovelInstance.save(failOnError:true)保存它,如果不验证,您将收到异常。

You probably have a validation error. Try calling validate() on it and inspecting the errors. Alternatively, try saving it with carroMovelInstance.save(failOnError: true) and you'll get an exception if it doesn't validate.

这篇关于Grails多个数据绑定域类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆