我创建了以下域类
class User implements Serializable {
private static final long serialVersionUID = 1
String username
String password
String mobile
String email
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static belongsTo = [organization : Organization,
branch : Branch,
student : Student]
Set<Role> getAuthorities() {
(UserRole.findAllByUser(this) as List<UserRole>)*.role as Set<Role>
}
static constraints = {
password blank: false, password: true
username blank: false, unique: true
organization nullable: true
branch nullable: true
student nullable: true
email nullable: true
mobile nullable: true
} }
但是当我在mysql中检查User表时,它仍显示分支,组织和学生NOT NULL
我在相关域中维护了hasOne关联。例如
class Organization { ... static hasOne = [user: User] }
我怀疑,是否有一个对此有任何影响
答案 0 :(得分:0)
hasOne创建非空约束。您必须在相关域中使用hasMany关系才能使用null。