id are exposed as a string but are not always really of string type:
"id": { "type": "Buffer", "data": [ 95, 124, 143, 224, 215, 119, 113, 55, 116, 183, 176, 46 ] }
So, I need to do this:
if (typeof sub.id !== 'string') { sub.id = new NativeId(sub.id).toHexString(); }
That is happening when there is a reference inside a sub structure.
For example:
@Model()
export class Homework {
@ID()
id: string;
@ArrayMember(HomeworkStudent )
students: HomeworkStudent [];
}
@Model()
export class Student {
@ID()
id: string;
}
@Model()
export class HomeworkStudent {
@Member()
student: Student; // This id will be exposed as string but will actually be of type of buffer.
@Member()
addedOn: Date;
}
It has been fixed in commit 768f94a736298caf5fdd641b86d08e6e13dcbce4 deserialization now supports persistent models inside non-persistent model (@Model with no ID)
It will be updated on NPM shortly.
id are exposed as a string but are not always really of string type:
"id": { "type": "Buffer", "data": [ 95, 124, 143, 224, 215, 119, 113, 55, 116, 183, 176, 46 ] }
So, I need to do this:if (typeof sub.id !== 'string') { sub.id = new NativeId(sub.id).toHexString(); }
That is happening when there is a reference inside a sub structure.For example:
so I end up using string instead: