我正在开发一个需要带有子类别的类别的网站。
我当前的域类是:
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/