Hello, I am trying to define a schema (using TypeScript) and I am encountering the following error:
Error: Exception in HostFunction: Schema validation failed due to the following errors:
- Property 'SomeObject.testKey' of type 'object' has unknown object type 'Array'
This is vaguely what the schema looks like, as I’ve defined it:
export class SomeObject extends Realm.Object<SomeObject> {
_id!: Realm.BSON.UUID = new Realm.BSON.UUID();
userId!: string;
name!: string;
createdAt!: Date = new Date();
lastUpdated!: Date = new Date();
testObject: EmbeddedObjectClass;
testKey?: Array<SomeClass>;
// Realm.List leads to the same error
// except with "List" instead of "Array" as the unknown object type
static generate({name, userId=NO_SYNC_USER_ID} testObject, testKey=[]}: {
name: string,
userId: string | undefined,
testObject: EmbeddedObjectClass,
testKey: Array<SomeClass>
}) {
return {
name,
userId: userId,
testObject: testObject
testKey: testKey,
}
}
}
So I’ve somehow gotten embedded objects to work, and I can somewhat simulate an array using an embedded object (arrays in documents are meant to be limited, so having predefined keys isn’t the worst thing in the world), but I can’t seem to get lists
or JavaScript Array
s to work—which would be much easier (and perhaps optimal?) to work with.
For me, the big question is: How do I get lists/arrays to work in Realm—how do I write lists to documents?
Note, also, that if I set the type, testKey: any
or testKey: SomeClass[]
, and pass an array of SomeClass
objects in the constructor, I get a silent failure: the application runs, nothing crashes, I don’t get an error message, but the array never gets written to the resultant Realm object/document.
I also cannot define a separate, static schema = {...}
, as this leads to the following error:
[Error: TransformError <path_to_file_defining_schema_class>:
Classes extending Realm.Object cannot define their own `schema` static,
all properties must be defined using TypeScript syntax]