我无法在Realm架构中指定type
作为primaryKey
。
以下是我的架构类型:
class EventKey extends Realm.Object{}
EventKey.schema = {
name: 'EventKey',
properties: {
rideid: { type: 'int', indexed: true },
ts: {type: 'int', indexed: true}
}
};
class Events extends Realm.Object{}
Events.schema = {
name: 'Events',
primaryKey: 'eventKey',
properties: {
eventKey: {type: 'EventKey'},
devid: { type: 'int'},
lat: {type: 'float'},
lng: {type: 'float'},
alt: {type: 'float'},
spd: {type: 'float'},
brg: {type: 'float'},
hepe: {type: 'float'},
vepe: {type: 'float'},
ang: {type: 'float'},
temp: {type: 'float'},
motion: {type: 'bool'},
ignition: {type: 'bool'},
mainPower: {type: 'bool'},
relayState: {type: 'bool'},
}
};
我想将EventKey
类型中的Events
类型用作primaryKey
。但它抛出一个例外说:
Schema validation failed due to the following errors:
- Property 'Events.eventKey' of type 'object' cannot be made the primary key.
换句话说,我想在领域中创建UNIQUE_INDEX
,这将阻止针对rideid and ts
的任何重复输入。怎么解决这个问题?