我有两个表用户角色

为了安全起见,这两个表应具有双向关系,因此我遵循了Users表中的 hasOne 组合,而角色表中的属于。但是双向关系并没有发生。

有人可以帮忙吗?

class User
{

    Long number
    Integer inhabitants

    static hasOne = [ role: Role]

    static constraints = {
        role nullable: true, unique: true
    }
}

class Role
{

     Users user
     static belongsTo = [user: Users ]
     static constraints = {
     }
}

最佳答案

Role更改为

class Role
{

     Users user
     static belongsTo = [user: User ] //you previously had Users here
     static constraints = {
     }
}

关于grails - Grails 2.4.4:hasOne无法解决双向关系,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35741556/

10-13 05:10