Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 类型';对象';无法使其成为主键_React Native_Realm - Fatal编程技术网

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'},
  }
};
我想在type
Events
中使用type
EventKey
作为
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
的任何重复条目。如何解决这个问题?

您可以将它们连接到一个字符串中,然后将其用作主键是的,但这是唯一的方法吗?是的,基本上是这样。