如何使用.properties关联新的域类?
我有以下类:
class Employer {
static hasMany = [employees: Employee]
}
class Employee {
String name
static belongsTo = [employer: Employer]
}
我尝试从前端保存一些 JSON(实际代码更加动态):
params = {
employer: 1,
name: 'Test'
}
def save = {
def employee = new Employee()
employee.properties = params;
employee.save()
}
但是,保存失败,因为无法从 id 设置雇主。 (无法将“java.lang.Integer”类型的属性值转换为所需类型“Employer”)有没有办法使其工作?
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):
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. (Failed to convert property value of type 'java.lang.Integer' to required type 'Employer') Is there a way to make that work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 JSON 结构不正确。它需要更像是:
The structure of your JSON is incorrect. It would need to be something more like: