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 没有保存。我无法弄清楚。任何帮助将不胜感激。
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()
}
The CarroInstance is saving, but the carroMovelInstance isn't. I cannot figure it out. Any help would be apreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能遇到验证错误。尝试对其调用
validate()
并检查错误。或者,尝试使用carroMovelInstance.save(failOnError: true)
保存它,如果它未验证,您将收到异常。You probably have a validation error. Try calling
validate()
on it and inspecting the errors. Alternatively, try saving it withcarroMovelInstance.save(failOnError: true)
and you'll get an exception if it doesn't validate.