Realm React-Native中的嵌套对象 [英] Nested Objects in Realm React-Native

查看:173
本文介绍了Realm React-Native中的嵌套对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

Realm React Native如何通过父子嵌套关系中的两种方式进行链接?

How does Realm React Native perform with two way linking in parent-child nested relationships?

示例

我有一个由InvoiceLines组成的Invoice对象.在旧数据库中,InvoiceLine表中的每一行都有对其父发票ID的引用.因此,可以使用简单的'WHERE ID =查询来从InvoiceLine到其Invoice或从Invoice到其所有InvoiceLines.

I have an Invoice object, which is made up of InvoiceLines. In the old database, each row in the InvoiceLine table had a reference to its parent Invoice's ID. So a simple 'WHERE ID= " query to get from either an InvoiceLine to its Invoice or an Invoice to all of its InvoiceLines.

在Realm中,我将具有以下模式(解释):

In Realm, I'm going to have the following schema (paraphrased):

class Invoice {};
Invoice.schema = {
  name: 'Invoice',
  properties: {
    ...
    lines: {type: 'list', objectType: 'InvoiceLine'}
  }
}

class InvoiceLine {};
InvoiceLine.schema = {
  name: 'InvoiceLine',
  properties: {
    ...
    invoice: 'Invoice',
  }
}

与使用ID并在Realm中以传统方式进行操作相比,这种直接链接的性能如何?是否存在存储所有这些链接的内存折衷方案?

How does the performance of this direct linking compare with using ID's and doing it the traditional way within Realm? Is there a memory tradeoff to store all of those links?

推荐答案

在大多数情况下,使用链接的效果应几乎与使用ID相同或更好.跟随链接比通过ID查找要快得多.您唯一遇到的性能问题就是删除对象时.删除父类的实例时,指向删除的父代的所有子链接都设置为null.无论如何,这可能是您想要完成的事情.删除子对象时,有时需要进行一些内部记账,但通常这足够快以至于无法察觉.

Using links should perform almost identically or better than using ID's in most cases. Following links will be much faster than looking up by ID. The only performance hit you will have is when deleting objects. When deleting instances of the parent class all child links pointing to the deleted parent are set to null. This is something that you probably want done anyway. When deleting child objects sometimes there is some internal bookkeeping that needs to be updated, but this is generally fast enough to be imperceptible.

这篇关于Realm React-Native中的嵌套对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆