Nested Objects in Realm React-Native

岁酱吖の 提交于 2019-12-07 16:34:38

问题


Question

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

Example

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.

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',
  }
}

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?


回答1:


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.



来源:https://stackoverflow.com/questions/36143953/nested-objects-in-realm-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!