使用uuid进行领域js查询

时间:2019-01-29 22:31:57

标签: react-native realm-js

您好,我在领域中拥有以下模型:

export const AddressSchema = {
  name: ADDRESS_SCHEMA,
  primaryKey: 'addressid',
  properties: {
    addressid: 'string',
    name: 'string?',
    region: 'int',
    from_api:'bool'
  }
}

export const PosSchema = {
  name: POS_SCHEMA,
  primaryKey: 'posid',
  properties: {
    posid: 'string',
    name: 'string?',
    address:ADDRESS_SCHEMA ,
    lat: 'double?',
    long: 'double?',
    from_api: 'bool',
  }
}
export const SmokerSchema = {
  name: SMOKER_SCHEMA,
  primaryKey: 'smokerid',
  properties: {
    smokerid: 'string',
    first_name: 'string?',
    last_name: 'string?',
    mobile: 'int?',
    gender: 'bool?',
    age: 'int?',
    occupation: 'int?'
  }
}

export const SwitchSchema = {
  name: SWITCH_SCHEMA,
  primaryKey: 'switchid',
  properties: {
    switchid: 'string',
    smoker: { type: SMOKER_SCHEMA },
    time: 'string?',
    count_outers: 'int?',
    count_packs: 'int?',
    new_brand: 'int?',
    new_sku: 'int?'
  }
}

export const SurveySchema = {
  name: SURVEY_SCHEMA,
  primaryKey: 'surveyid',
  properties: {
    surveyid: 'string',
    bool_switch: 'bool?',
    user: 'int?',
    date:'string',
    behalf: 'int?',
    reason: 'int?',
    shift: 'int?',
    current_brand: 'int?',
    current_sku: 'int?',
    switch: {type: SWITCH_SCHEMA},
    pos_id:'string?',
    new_brand:'int?',
  }
}

export const UploadSchema = {
  name: UPLOAD_SCHEMA,
  primaryKey: 'uploadid',
  properties: {
    uploadid: 'string',
    date:'string',
    brand:'int',
    user:'int',
    pos: 'int',
    img:'string'
  }
}

并且我将uuid用作所有模型的主键,当我想遍历所有POS对象并获取每个pos的测量和上载时,我遇到了问题,所以我遇到了此错误 enter image description here 编写此代码后

Realm.open(databaseOptions).then(realm => {
            let all_pos = realm.objects(schemas.POS_SCHEMA);

            let success_pos_count = 0;
            let pos_to_sync = []

            all_pos.forEach(pos => {

                let pos_data = {}
                let surveys = realm.objects(schemas.SURVEY_SCHEMA).filtered('pos_id LIKE"'+ pos.posid +'"');
                let uploads = realm.objects(schemas.UPLOAD_SCHEMA).filtered('pos LIKE"'+ pos.posid +'"');
});

});

所以在这里,我正在查询以获取POS,然后使用forEach循环将其循环并获得调查,具有特定uuid的上载,因此我坚持此错误,因此请提供帮助并感谢您前进。

0 个答案:

没有答案