Realm Db 获取父子对象重复无穷次

问题描述 投票:0回答:0

我有一个如下所示的领域数据库模式。

const ParentSchema = {
  name: 'parent',
  properties: {
    id: 'string',
    father_name: 'string',
    children: { type: 'linkingObjects', objectType: 'child', property: 'parent' },
  },
  primaryKey: 'id',
};


const ChildSchema = {
  name: 'child',
  properties: {
    id: 'string',
    first_name: 'string',
    parent: { type: 'parent' },
  },
  primaryKey: 'id',
};

首先我想知道亲子关系是否可以?我需要父母和他们的孩子以及孩子和父母。

问题是当我得到孩子时,我得到了他父母的孩子名单,而父母又有了孩子名单,孩子有父母,父母又有孩子。这样下去......

当我得到父母名单时,这同样适用。

let data = realm.objects('parent');
realm realm-mobile-platform realm-list realm-migration
© www.soinside.com 2019 - 2024. All rights reserved.