I have an issue with Grails new json-views and a one-to-many association. The following code is working:
Class Foo:
class Foo {
String name
static hasMany = [bars:Bar]
static constraints = {
}
}
Class Bar:
class Bar {
String name
Foo foo
static constraints = {
}
}
Json view for foo (show.gson):
model {
Foo foo
}
json {
foo g.render(template:"foo", model:[foo:foo])
}
_foo.gson template:
model {
Foo foo
}
json {
name foo.name
bars foo.bars.collect { it.id }
}
But if I change the foo class to use a List instead like this:
class Foo {
String name
List bars
static hasMany = [bars:Bar]
static constraints = {
}
}
I get the following error :
[Static type checking] - No such property: id for class: java.lang.Object @ line 13, column 29. bars foo.bars.collect { it.id }
I am sure there are ways around this but I was wondering if anyone has experienced this and know of why it doesn't work when a List is used.
Many thanks for your help.