我有以下域:用户、角色、公司。User 和 Role 是 m:n 关系,Company to User 是 1:m,User to Company 是 1:1。我对用户域的定义有疑问。这里是:
class User {
static hasMany = [authorities: Role ]
static belongsTo = [ Role , Company ]
}
我想从用户访问公司,以便 user.company 将给我分配他的公司。不允许这种修改:
static belongsTo = [ Role , company: Company ]
这是错误:
Unexpected node type: EXPR found when expecting type: LABELED_ARG at line: 9 column: 41. File: /Users/alfred/Applications/grails_projects/extramile/grails-app/domain/fbm/extramile/User.groovy @ line 9, column 41.
请注意,也不能这样做:
static belongsTo = [ role: Role , company: Company ]
由于 User-Role 具有 m:n(也已由 'authorities' 变量指定)。
还有其他解决方法吗?谢谢。