0

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.

2
  • Please file a request at github.com/grails/grails-views/issues and we will take a look. Thanks for the feedback. Commented May 12, 2016 at 12:57
  • @jeff-scott-brown Thanks! Request created here link Commented May 12, 2016 at 14:03

1 Answer 1

0

As noted on the issue at https://github.com/grails/grails-views/issues/38, the collection needs to be declared as List<Bar> bars, not List bars.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.