我有这个代码:
void updateIndex() {
Visit.withNewSession {
def results = patient.visits.sort{ it.date }
results.eachWithIndex { item, index ->
item.index = index
}
}
}
这在没有 save() 的情况下保存到数据库。我将结果更改为使用 findAll 查询(因为我只想选择它们),现在它不会将更改保存到数据库中。我确实看到了索引的变化,但这些变化永远不会持续存在。
def results = Visit.findAllByPatientAndTypeInList(
this.patient,
[Type.Test, Type.Junk]
).sort{ it.date }
这是 GORM 的陷阱之一吗?我试图显式调用保存(并检查是否有任何错误),但仍然没有运气。