grails - 此树结构的理想Grails类域是什么

标签 grails tree-structure

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

我当前的域类是:

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
    } 
}

但这给了我一个错误:

Property [children] in class [class com.abc.Category] is a bidirectional one-to-many with two possible properties on the inverse side. Either name one of the properties on other side of the relationship [category] or use the 'mappedBy' static to define the property that the relationship is mapped with. Example: static mappedBy = [children:'myprop']

最佳答案

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

关于grails - 此树结构的理想Grails类域是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16663069/

相关文章:

validation - Grails:重复项和唯一约束验证

mongodb - 在 MongoDB 中对集合进行递归搜索

Python递归将元组列表排序为树结构

javascript - 如何将数组转换为N叉树?

javascript 树结构 - 遍历树结构并显示子项内计数属性的总和

linux - 如何配置grails类路径以添加 "src/groovy"文件夹(在Linux环境中)?

引用 png 的 Grails svg 图像 href 未显示

grails - 有没有办法做 gsp partials 而不是标签库?

grails - 如何使用 Grails 获得测试覆盖率?

php - 使用 PHP 创建一个高效的好友列表