Grails有很多关系错误

时间:2013-11-05 12:55:27

标签: grails gorm

由于我对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
    }
}

1 个答案:

答案 0 :(得分:1)

像这样更改课程:

class Project {

    ...
    Site site
    Sector sector

    static belongsTo = [Site, Sector]
}