I went through the realm-js documentation and was unable to find any examples explaining how to push an object into the array property of its parent.
To be a little more clear, I have a Schema Test
which has a property data: {type: "data[]", default: []}
, however I am unable to push any data
objects to it.
Here is the error I get.
Property must be of type 'data', got ([object RealmObject])
This is what I tried:
this.realm.write(()=>{
const dataObj = this.realm.create('data', data);
this.user.test.data.push(dataObj);
})
What am I doing wrong?
I also tried to directly push the data directly, but I get a similar error.
class Test{
}
Test.schema = {
name: "test",
primaryKey: "id",
properties: {
id: "string",
start: "date?",
duration: "int", //in seconds
capsule_id: "string",
creation: "date",
status: "int",
height: "float",
weight: "float",
time_of_evolution: "string",
treatment: "bool",
data: {type: "data[]", default: []},
symptoms: {type: "symptom[]", default: []},
meals: {type: "meal[]", default: []},
device: "device?",
ph11: "int?",
ph71: "int?",
ph12: "int?",
ph72: "int?",
cardinal_symptoms: {type: "cardinal_symptom[]", default: []},
}
};
export default Test;
class DeviceData{}
DeviceData.schema = {
name: 'data',
primaryKey: "timestamp", //check to see if this is a good idea
properties: {
ph1: 'int',
ph2: 'int',
x: 'int',
y: 'int',
z: 'int',
timestamp: 'int',
raw: 'string' //base64, incase something went wrong
}
};
export default DeviceData;
data
is a reserved word for realm since it already has a data type as data
. If the schema name changed to something else problem will be solved.
Realm supports the following basic types: bool, int, float, double, string, data, and date.
bool
properties map to JavaScriptboolean
valuesint
,float
, anddouble
properties map to JavaScript number values. Internallyint
anddouble
are stored as 64 bits whilefloat
is stored with 32 bits.string
properties map tostring
data
properties map toArrayBuffer
date
properties map toDate