Grails形成了多对一的创建
我是Grails形成了多对一的创建,grails,grails-2.0,gsp,Grails,Grails 2.0,Gsp,我是grails的初学者,我有一个基本问题。我想在子类窗体创建中显示父类实例的列表 我的域类如下。父类是Company class Company { String name static constraints = { name(blank:false) } String toString(){name} } 我的孩子班是公司所在地 class Location { String name String address
grails
的初学者,我有一个基本问题。我想在子类窗体创建中显示父类实例的列表
我的域类如下。父类是Company
class Company {
String name
static constraints = {
name(blank:false)
}
String toString(){name}
}
我的孩子班是公司所在地
class Location {
String name
String address
static belongsTo= {companyLocation:Company}
static constraints = {
name(blank: false)
address blank:false
}
String toString(){"company:"+companyLocation+"Location:"+name}
}
现在在位置视图的\u表单模板'中,我有了公司位置下拉列表的代码`
<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>
当我在位置域
类中定义了静态变量companyLocation
时,为什么会出现此错误?能告诉我哪里出了问题吗
提前感谢。这看起来像是语法问题
static belongsTo= {companyLocation:Company}
应该是
static belongsTo= [companyLocation:Company]
还有一种面向对象的方法可以做到这一点,而不是使用有很多,属于
创建另一个CompanyLocation域类
Class CompanyLocation {
Company company
Location location
static constraints = {
company(blank:false, nullable:false)
location(blank:false, nullable:false)
}
public String toString() {
return "${company} ${location}"
}
}
Class CompanyLocation {
Company company
Location location
static constraints = {
company(blank:false, nullable:false)
location(blank:false, nullable:false)
}
public String toString() {
return "${company} ${location}"
}
}