类型'对象'不能成为主键

时间:2017-06-09 08:44:34

标签: react-native realm

我无法在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的任何重复输入。怎么解决这个问题?

0 个答案:

没有答案