[英]How to push a schema object into the array property of another schema object?
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. 我浏览了realm-js 文档 ,却找不到任何示例来说明如何将对象推入其父对象的array属性。
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. 为了更清楚一点,我有一个模式
Test
,该Test
具有属性data: {type: "data[]", default: []}
,但是我无法将任何data
对象压入其中。
Here is the error I get. 这是我得到的错误。
Property must be of type 'data', got ([object RealmObject])
属性必须为'data'类型,已获取([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
. data
是领域的保留字,因为它已经具有数据类型为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.
Realm支持以下基本类型:bool,int,float,double,string,data和date。
bool
properties map to JavaScriptboolean
valuesbool
属性映射到JavaScriptboolean
值int
,float
, anddouble
properties map to JavaScript number values.int
,float
和double
属性映射到JavaScript数字值。 Internallyint
anddouble
are stored as 64 bits whilefloat
is stored with 32 bits.内部
int
和double
存储为64位,而float
存储为32位。string
properties map tostring
string
属性映射到string
data
properties map toArrayBuffer
data
属性映射到ArrayBuffer
date
properties map toDate
date
属性映射到Date
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.