【发布时间】:2013-11-05 12:55:26
【问题描述】:
由于我对 GORM 和 Grails 中的域对象建模知识贫乏,我遇到了一个问题。
这是我的问题:
| Error Error loading plugin manager:
No owner defined between domain classes [class com.myproject.model.Project] and
[class com.crowdfun.Sector] in a many-to-many relationship.
Example: static belongsTo = com.myproject.model.Sector
(Use --stacktrace to see the full trace)
我不能说哪里出了问题,因为我按照官方grails文档的教程:http://grails.org/doc/latest/guide/GORM.html#manyToMany
我的课:
Project.groovy:
class Project {
String name
Integer nbInvestors
Region region
Integer nbDays
Boolean success
String equity
String currency
Double target
Double raisedAmount
String url
Double valuation
boolean extended = false
static belongsTo = [
site: Site,
sector: Sector
]
static hasMany = [
sectors: Sector
]
static hasOne = [
valuationRange: ValuationRange,
targetRange: TargetRange
]
static constraints = {
name nullable: true
nbInvestors nullable: true
region nullable: true
nbDays nullable: true
success nullable: true
equity nullable: true
currency nullable: true
target nullable: true
raisedAmount nullable: true
url nullable: true, unique: true
valuation nullable: true
}
}
Sector.groovy:
class Sector {
String name
static hasMany = [
projects: Project
]
static constraints = {
name unique: true
}
@Override
public String toString() {
return name
}
def getNbProjects() {
projects.size()
}
}
Site.groovy
class Site {
String name
static hasMany = [
projects: Project
]
static constraints = {
name unique: true
}
@Override
public String toString() {
return name
}
}
【问题讨论】:
-
错误是不言自明的。使用
belongsTo = Sector表示 m-m 关系。 -
我不能这样做,因为我曾经在我的项目类中添加过 belongsTo 关系。所以我这样做了: static belongsTo = [ site: Site, sector: Sector ] 似乎是正确的不?
-
再次逐行、逐字、逐句地按照相同的教程进行操作。 :)
标签: grails grails-orm