1

我正在开发一个需要带有子类别的类别的网站。

我当前的域类是:

package com.abc

class Category {

    String title
    String description
    Category parent

    static hasMany = [children: Category, listing: Listing]

    static constraints = {
        title blank: false
        description blank: true
    } 
}

但这给了我一个错误:

类 [class com.abc.Category] ​​中的属性 [children] 是双向的一对多,在反面有两个可能的属性。要么命名关系 [类别] 另一侧的属性之一,要么使用“mappedBy”静态定义关系映射的属性。示例:静态 mappedBy = [children:'myprop']

4

1 回答 1

4

我只会使用Category parent. 我们总能得到孩子Category.findAllByParent。这也是稍后在树创建中使用的最简单的解决方案。

于 2013-05-21T07:15:08.687 回答