我是grails
的初学者,我有一个基本问题。我想在子类表单创建中显示父类实例的列表。
我的Domain类如下。父类是公司。
class Company {
String name
static constraints = {
name(blank:false)
}
String toString(){name}
}
我的 child 类(class)是公司的所在地。
class Location {
String name
String address
static belongsTo= {companyLocation:Company}
static constraints = {
name(blank: false)
address blank:false
}
String toString(){"company:"+companyLocation+"Location:"+name}
}
现在在
_form template' of location view I have the code for the
companyLocation下拉列表中`<div class="fieldcontain ${hasErrors(bean: locationInstance, field: 'companyLocation', 'error')} required">
<label for="companyLocation">
<g:message code="location.companyLocation.label" default="companyLocation" />
<span class="required-indicator">*</span>
<g:select id="companyLocation" name="companyLocation.id" from="${first_project.Company.list()}" optionKey="id" required="" value="${locationInstance?.companyLocation?.id}" class="many-to-one"/>
</label>
</div>
当我转到创建页面时,出现错误:
Error 500: Internal Server Error
URI /first_project/location/create
Class groovy.lang.MissingPropertyException
Message No such property: companyLocation for class: first_project.Location
当我在
companyLocation
类中定义了静态变量Location Domain
时,为什么会出现此错误?可以让我知道我哪里出了问题吗?提前致谢。
最佳答案
这看起来像语法问题,
static belongsTo= {companyLocation:Company}
应该真的
static belongsTo= [companyLocation:Company]
关于grails - 用于多对一的归属的Grails表单创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20171921/