Grails关闭Eager Fetching hasMany with Restful Controller或Resource

时间:2016-02-24 03:56:01

标签: rest grails gorm

以域类UserRole为例:

@Resource(uri='/api/user', formats=['json', 'xml'])
class User {
    String username
    String password
    static hasMany = [roles: Role]
}

@Resource(uri='/api/role', formats=['json', 'xml'])
class Role {
    String authority
    static hasMany = [users: User]
    static belongsTo = [User]
}

/api/user/api/user/1都会获取关联的Role个对象。如何使/api/user仅返回获取相关User个对象的Role个对象WIHTOUT列表,而/api/user/1将返回Userid=1个对象}和关联的Role对象?

1 个答案:

答案 0 :(得分:0)

您可以通过...编写自己的实现来完成此操作。 Grails的@Resource实现不支持您正在寻找的这些非常具体的功能。实现您自己的管理fetchMode的控制器,以满足您自己的需求。