Reputation: 33
I have two tables Users and Role
These two tables should have bi-directional relationship for security purposes, so I have followed hasOne combination in Users table and belongs to in Role table. But bi-directional relationship is not happening.
Can anyone please help in this ?
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 = {
}
}
Upvotes: 2
Views: 113
Reputation: 729
I use Grails Plugin spring-security-core and these two pages to help me setup. Simplified Spring Security with Grails and Tutorials - Reference Documentation. It creates a table called UserRole that takes care of all that.
Upvotes: 0
Reputation: 589
Change Role
to
class Role
{
Users user
static belongsTo = [user: User ] //you previously had Users here
static constraints = {
}
}
Upvotes: 1