我有一个域对象 Department
,它与另一个域对象 DepartmentPreference
具有一对一的关系。当我尝试为 Department
生成脚手架 Controller 时,我会看到一个下拉菜单来选择 DepartmentPreference
。由于还没有(因为 DepartmentPreference
有一个 belongsTo = Department
),所以我无法创建一个。
您可以推荐的最佳解决方案是什么?
最佳答案
您是否像为 Department 那样为 DepartmentPreference 创建了 Controller / View ?如果没有,您将需要创建一个或添加/修改现有的 Controller / View 来处理该功能。
既然您提到了脚手架 - 我假设您的部门 Controller 的定义如下:
class DepartmentController {
static scaffold = true
..
}
或
class SomeController {
static scaffold = Department
..
}
如果这个部门 Controller - 是自动生成的或仅使用脚手架定义,那么它仅为部门提供 CRUD 操作,而不是任何其他域类(至少不是直接提供)。有很多方法可以添加缺少的 DepartmentPreference 功能,但对您来说最快的方法可能是使用在 DepartmentPreference 上创建部门 Controller 的任何方法。
关于grails - GORM 与 grails 脚手架一对一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12966075/