RLM_ERR_SCHEMA_VALIDATION_FAILED - 数组的领域 (MongoDB) 架构验证问题

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

我有几个简单的 RealmObject 类,如下所示:

class Patient : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var firstName: String = ""
var lastName: String = ""
var visits: RealmList<PelletInsertionVisit> = realmListOf()
var lastFourOfSSN: String = ""
}

class PelletInsertionVisit : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var visitDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)
var pelletsUsed: RealmList<Pellet> = realmListOf()
}

class Pellet: EmbeddedRealmObject {
var size = PelletSize.ZERO.value
var lotNumber: String = "UNKNOWN"
}

当我执行此代码时,打开会引发异常:

fun openPatientRealm() : Realm {
val configuration = RealmConfiguration.create(schema = setOf(Patient::class))
Logger.d("About to open Realm Configuration: $configuration")

try {
    val realm = Realm.open(configuration)  //EXCEPTION HERE

    Logger.d("Realm opened: : ${realm.toString()}")

    return realm
}
catch (ex: Exception) {
    Logger.e("Exception caught: " + ex.message)
    Logger.e("Stack trace: " + ex.stackTraceToString())
}

throw Exception("Realm Could Not be Opened")
}

例外情况是:

[RLM_ERR_SCHEMA_VALIDATION_FAILED]:架构验证由于以下错误而失败:

  • “array”类型的属性“PelletInsertionVisit.pelletsUsed”具有未知的对象类型“Pellet”

请问我做错了什么?在我看来,就像文档说它应该使用 EmbeddedRealmObject 但我遗漏了一些东西。

realm kotlin-multiplatform realm-list
1个回答
0
投票

问题出在配置上。长话短说,您必须告诉它您打算使用的所有类。所以,它去了:

val configuration = RealmConfiguration.create(schema = setOf(Patient::class, Pellet::class, PelletInsertionVisit::class, PelletLot::class))
© www.soinside.com 2019 - 2024. All rights reserved.