Realm Kotlin SDK:无法在写入事务之外修改托管列表

问题描述 投票:0回答:1

我不明白为什么会出现此错误。我正在写事务中完成所有操作,对吗?

activeSchoolClassNotNull { activeSchoolClass ->
    val schoolSubjects = ocjeneSkoleScraper.getSubjects()
    realm.write {
        activeSchoolClass.schoolSubjects = schoolSubjects.toRealmList()
        copyToRealm(activeSchoolClass, updatePolicy = UpdatePolicy.ALL)
        [email protected] = activeSchoolClass
    }
}

谁能告诉我我做错了什么?

kotlin realm
1个回答
0
投票

问题是我需要在修改它之前从领域获取最新的对象。

realm.write {
    val latestObj = findLatest(obj)
    latestObj.someProperty = "changed"
    copyToRealm(latestObj)
}
© www.soinside.com 2019 - 2024. All rights reserved.