React native 类型';对象';无法使其成为主键
我无法在域架构中指定React native 类型';对象';无法使其成为主键,react-native,realm,React Native,Realm,我无法在域架构中指定类型作为我的主密钥 以下是我的模式类型: 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{} E
类型
作为我的主密钥
以下是我的模式类型:
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'},
}
};
我想在typeEvents
中使用typeEventKey
作为primaryKey
。但它抛出了一个例外,即:
Schema validation failed due to the following errors:
- Property 'Events.eventKey' of type 'object' cannot be made the primary key.
换句话说,我想在realm中创建
UNIQUE_INDEX
,这将防止针对rideid和ts
的任何重复条目。如何解决这个问题?您可以将它们连接到一个字符串中,然后将其用作主键是的,但这是唯一的方法吗?是的,基本上是这样。