【问题标题】:What is the ideal Grails class domain for this tree structure这种树结构的理想 Grails 类域是什么
【发布时间】:2013-05-21 05:55:44
【问题描述】:

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

我当前的域类是:

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']

【问题讨论】:

标签: grails tree-structure


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    相关资源
    最近更新 更多