Grails 使用来自其他域的对象渲染视图

Grails render view with objects from other domains

我有两个相关的域对象。

首先是:

class VideoCategory {

    String videoCategoryName

    static constraints = {
        videoCategoryName nullable: false
    }
}

那么我有:

class Video {

    VideoCategory videoCategory
    String fileName
    String videoTitle
    String videoDescription

    static constraints = {
        fileName nullable: false
        videoTitle nullable: true
        videoDescription nullable: true
    }
}

我想要的是一个视频创建页面,它不会显示来自 VideoCategory 对象的 videoCategoryId,而是脚手架下拉列表中的 videoCategoryName 本身。我想将 id 用作 FK,但呈现名称...然后在保存时我想保存 id。我对 Java/Groovy 的思维方式还很陌生。在 python/flask 中,我可能只是确保所有对象都导入到我的视图中,然后我可以直接调用它们并 render_view 使用该数据,然后嵌入 id 作为保存的值在标记中呈现 videoCategoryName 值。

将此添加到视频类别 class:

String toString() {
    return videoCategoryName
}