【问题标题】:How to write a RealmList in a node realm schema如何在节点领域模式中编写 RealmList
【发布时间】:2017-12-13 10:17:20
【问题描述】:

我有一个 OrderEntry 架构,其中包含另一个领域对象 ItemEntry 的 RealmList:

export const OrderEntrySchema: Realm.ObjectSchema = {
 name: 'OrderEntry',
 primaryKey: '_id',
 properties: {
  ...
  items: ???
 }
}

export const ItemEntrySchema: Realm.ObjectSchema = {
 name: 'ItemEntry',
 primaryKey: 'id',
 properties: {
  ...
  }
}

如何将项目定义为RealmList<ItemEntry> 可以在android 中完成?

注意:两个架构都在不同的文件中。

【问题讨论】:

    标签: node.js realm realm-mobile-platform realm-list


    【解决方案1】:

    您可以像这样指定 ItemEntry 列表

    items: {type: 'list', objectType: 'ItemEntry'}
    

    这是您的架构的示例。

    const OrderEntrySchema = {
        name: 'OrderEntry',
        primaryKey: 'id',
        properties: {
            id: 'string',
            items: {type: 'list', objectType: 'ItemEntry'}
        }
    };
    
    const ItemEntrySchema = {
        name: 'ItemEntry',
        primaryKey: 'id',
        properties: {
            id: 'string'
        }
    };
    

    如果要将它们放在单独的文件中,则需要在文件中使用 OrderEntry 导入 ItemEntry

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-27
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多