简体   繁体   English

grails 3-获取子域对象

[英]grails 3 - get child domain objects

I have looked at this Grails get child domain objects but I am still lost. 我已经看过这个Grails获取子域对象,但是我仍然迷路。

I have added to conf/application.yml 我已经添加到conf / application.yml

converters:
    encoding: UTF-8
    grails.converters.json.default.deep: true

But when I do a get on a domain, I still get 但是当我进入某个域时,我仍然会

[~]$ curl http://localhost:8080/request/2 {"id":2,"stream":{"id":2},"release_label":"ABC_4.3","date_created":"2017-08-21T13:06:27Z","envs":[{"id":1}],"status":"init"} [〜] $ curl http:// localhost:8080 / request / 2 {“ id”:2,“ stream”:{“ id”:2},“ release_label”:“ ABC_4.3”,“ date_created”:“ 2017-08-21T13:06:27Z”, “ENVS”:[{ “ID”:1}], “状态”: “初始化”}

I want stream and envs to be expanded to give all of the records, not just the id. 我希望将流和envs扩展为提供所有记录,而不仅仅是ID。

So Request,groovy is 所以Request,groovy是

And Stream.groovy is 并且Stream.groovy是

package test
import grails.rest.*
class Stream {
    String name
    String feedgroup
    String description
    UnixGroup unixgroup
    String swid
    boolean powercentre = false
    String latest_release
    static hasMany = [envs: Env]

    static constraints = {
          name blank:false, unique: true
    }
}

package test
import grails.rest.*

class Request {
    Date date_created = new Date()
    Date date_completed
    String status = "init"
    String release_label
    Stream stream
    static hasMany = [envs: Env]

    static constraints = {
           date_completed nullable: true
    }
        static searchable = {
            only = [ 'stream', 'status' ]
        }
}

I am using Grails 3.30. 我正在使用Grails 3.30。

Is grails.converters.json.default.deep still valid for Grails 3? grails.converters.json.default.deep对Grails 3仍然有效吗? And how do I use it. 以及如何使用它。

I have been told on the grails slack page that converters are not used when the application profile is rest-api. 在grails松弛页面上,我被告知,当应用程序配置文件为rest-api时,不使用转换器。

Instead JSON views should be used. 相反,应使用JSON视图。 In the render, add an option deep: true 在渲染中,添加一个深选项:true

eg 例如

json g.render(book, [deep:true])

where book is the domain 书在哪里

For further info, see http://views.grails.org/latest/#_rendering_domain_classes 有关更多信息,请参见http://views.grails.org/latest/#_rendering_domain_classes

grails.converters.json.default.deep

Should be changed to just: 应该改为:

json.default.deep

as you are already in the grails.converters block. 因为您已经在grails.converters块中。

So it should look like: 所以它应该看起来像:

converters:
    encoding: UTF-8
    json.default.deep: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM