【问题标题】:Realm-js schema with nested objects具有嵌套对象的 Realm-js 模式
【发布时间】:2017-01-25 12:51:32
【问题描述】:

我想轻松查询这样的结果:

[{
  name: 'john_doe',
  info: {
    age: 24,
    notes: 'custom text',
    phoneNumbers: {
      home: 112345678,
      work: 1234567,
    },
  },
}, {...}, {...}...]

...通过这样的查询:

contacts.filtered("info.age = 24 AND info.notes CONTAINS 'custom'");

我应该如何创建这样的架构?文档对数据类型和嵌套属性非常困惑:

我不需要单独检索此数据的任何部分 - 只需一次包含所有嵌套对象的完整对象。

【问题讨论】:

    标签: react-native realm


    【解决方案1】:

    您可以将所有字段放入一个对象中:

    var ContactSchema = {
        name: 'Contact',
        properties: {
            name: 'string',
            age: 'int',
            notes: 'string',
            homePhone: 'string',
            workPhone: 'string'        
        }
    };
    

    或者,您可以为 info 和 phoneNumbers 创建子对象,但如果您没有在多个联系人之间共享此数据,则可能不需要这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 2016-02-21
      • 2016-01-05
      • 2016-06-02
      • 2021-05-24
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      相关资源
      最近更新 更多