Dody Rachmat Wicaksono
Dody Rachmat Wicaksono

Reputation: 1014

What is the ideal Grails class domain for this tree structure

I'm developing a website that need categories with sub categories.

My current domain class is:

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

But it gives me an error:

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

Upvotes: 1

Views: 525

Answers (1)

Grzegorz Gajos
Grzegorz Gajos

Reputation: 2363

I would use only Category parent. We can always get children by Category.findAllByParent. This is also the easiest solution to use later on in tree creation.

Upvotes: 4

Related Questions