0

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

我的课程 :

项目.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()
    }
}

网站.groovy

class Site {

    String name

    static hasMany = [
        projects: Project
    ]

    static constraints = {
        name unique: true
    }

    @Override
    public String toString() {
        return name
    }
}
4

1 回答 1

1

像这样更改类:

class Project {

    ...
    Site site
    Sector sector

    static belongsTo = [Site, Sector]
}
于 2013-11-05T13:13:32.047 回答