Object type cannot be made primary key

I cannot specify type

as my primaryKey

in the Realm schema.

Here are my types of circuits:

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'},
  }
};

      

I want to use a type EventKey

in a type Events

like primaryKey

. but it throws an exception:

Schema validation failed due to the following errors:
- Property 'Events.eventKey' of type 'object' cannot be made the primary key.

      

In other words, I want to create UNIQUE_INDEX

in an area that will prevent any duplicate write against rideid and ts

. How to solve this?

+3


source to share





All Articles