3

使用 React Native 和 Realm 的第一天,我很难弄清楚如何通过两个 Realm List Objects 执行查询。

TasksReservations, 有Renters, 有first_namelast_name领域。我希望我的用户能够按承租人的名字和姓氏搜索任务。

本质上,“给我所有租户的名字或姓氏以“xyz”开头的任务”

const TaskSchema = {
  name:'Task',
  properties: {
    reservations:{ type: LIST, objectType: ReservationSchema.name },
  }
},

const ReservationSchema = {
  name:'Reservation',
  properties: {
    renters:{ type: LIST, objectType: RenterSchema.name },
  },
}

const RenterSchema = {
  name:'Renter',
  properties: {
    first_name:{ type:STRING, optional:true },
    last_name:{ type:STRING, optional:true },
  },
}

我只是不知道如何设置我的查询和谓词来完成这个。

4

1 回答 1

3

您可以过滤嵌套对象。

let tasks = realm.objects('Dog');
let xyzTasks = task.filtered('reservations.renters.first_name BEGINSWITH "xyz" OR reservations.renters.last_name BEGINSWITH "xyz"');

参考:https ://realm.io/docs/react-native/latest/#filtering

于 2016-09-25T02:35:39.637 回答