当我创建一个简单对象并仅对该对象调用 save 方法时,所有可以为空的属性都以空值插入到数据库中。这只是在数据库中造成混乱。有没有办法避免这种情况?
- Grails 版本 - 2.5.6
- GORM 版本 - 6.0.12
- mongodb.engine = "映射"
领域 :
public class Person {
static constraints = {
name(nullable: true)
telecom(nullable: true)
gender(nullable: true)
birthDate(nullable: true)
address(nullable: true)
}
}
代码 :
Person person = new Person()
person.save()
Mongo 数据库条目
{
"_id" : NumberLong(59),
"address" : null,
"birthDate" : null,
"gender" : null,
"name" : null,
"telecom" : null,
"version" : 0,
"dateCreated" : ISODate("2020-04-18T15:34:26.244Z"),
"lastUpdated" : ISODate("2020-04-18T15:34:26.244Z")
}
数据库中的预期条目:
{
"_id" : NumberLong(59),
"version" : 0,
"dateCreated" : ISODate("2020-04-18T15:34:26.244Z"),
"lastUpdated" : ISODate("2020-04-18T15:34:26.244Z")
}
这曾经适用于旧版本的 GORM,这是默认行为,但是当我更新 GORM 版本时,我开始在数据库中获取所有这些空值,这只是增加了我的数据库的大小。