I have a couple of simple RealmObject classes that look like this:
type or paste code here
class Patient : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var firstName: String = ""
var lastName: String = ""
var visits: RealmList<PelletInsertionVisit> = realmListOf(PelletInsertionVisit())
var lastFourOfSSN: String = ""
}
class PelletInsertionVisit : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId()
var visitDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)
var pelletsUsed: RealmList<Pellet> = realmListOf(Pellet())
}
class Pellet: EmbeddedRealmObject {
var size = PelletSize.ZERO.value
var lotNumber: String = "UNKNOWN"
}
When I perform this code, the open throws an exception:
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")
}
The exception is:
[RLM_ERR_SCHEMA_VALIDATION_FAILED]: Schema validation failed due to the following errors:
- Property ‘PelletInsertionVisit.pelletsUsed’ of type ‘array’ has unknown object type ‘Pellet’
What is it that I am doing wrong, please? It looks, to me, to be like the documentation says it should be using the EmbeddedRealmObject but I’m missing something.