tags:

views:

549

answers:

1

I have the Grails domain classes Child and Toy. A child can have many toys.

class Child {
    static hasMany = [ toys : Toy ]
    String name
}

class Toy {
    static belongsTo = [ owner : Child ]
    String name
}

It was my understanding that there will be a toys property on Child. That is, there will be the Child method:

public Set getToys()

But this doesn't work. I'm unable to reference child.getToys() from a Java class. I have explicitly define toys in Child:

class Child {
    static hasMany = [ toys : Toy ]
    String name
    Set toys
}

Is this correct? Do I need to explicitly define a Set for a one-to-many relationship?

+3  A: 

Yes you have to expicitly define the property if you want to reference it from Java. This has to do with the way the groovy compiler (groovyc) creates the stub classes for the groovy beans.

Siegfried Puchbauer
See my post on [email protected]. The claim is this has been fixed in Grails 1.1. http://www.nabble.com/Define-Set-for-one-to-many-relationship--td21195999.html
Steve Kuo