[英]How to associate new domain class using .properties?
I have the following classes: 我有以下课程:
class Employer {
static hasMany = [employees: Employee]
}
class Employee {
String name
static belongsTo = [employer: Employer]
}
I try to save some JSON from the front end (the actual code is a bit more dynamic): 我尝试从前端保存一些JSON(实际代码更具动态性):
params = {
employer: 1,
name: 'Test'
}
def save = {
def employee = new Employee()
employee.properties = params;
employee.save()
}
However, the save fails because the employer cannot be set from the id. 但是,保存失败,因为无法通过id设置雇主。 (Failed to convert property value of type 'java.lang.Integer' to required type 'Employer') Is there a way to make that work? (无法将类型为'java.lang.Integer'的属性值转换为所需的类型为'Employer'的方法)有没有办法做到这一点?
The structure of your JSON is incorrect. JSON的结构不正确。 It would need to be something more like: 它应该更像是:
'employer':{
'class':'Employer','id':1
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.