1.

How You Can Create One-to-one Relationship In Gorm?

Answer»

There are two ways of specifying a one-to-one relationship:

FIRST Add an article PROPERTY and the unique constraint to the User domain:

class User {
Article article
STATIC CONSTRAINTS = {
article unique: TRUE
}
}
class Article {
static belongsTo = [user: User]
}

Second use the hasOne property on the owning (User) side:
class User {
static hasOne = [article: Article]
}
class Article {
static belongsTo = [user: User]
}

There are two ways of specifying a one-to-one relationship:

First Add an article property and the unique constraint to the User domain:

class User {
Article article
static constraints = {
article unique: true
}
}
class Article {
static belongsTo = [user: User]
}

Second use the hasOne property on the owning (User) side:
class User {
static hasOne = [article: Article]
}
class Article {
static belongsTo = [user: User]
}



Discussion

No Comment Found