Recursive Behaviour of Realm Model Objects with relationship


#1

Hi Team,

I am using realm for one of my application so designing Model Classes. While creating Models, I was having an issue explained below with example -

1- Suppose we have 5 classes
ClassA
-classAID
-status
-objClassB{ClassB}

ClassB
-classBID
-status
-objClassC{ClassC}

ClassC
-classCID
-status
-objClassD{ClassD}

ClassD
-classDID
-status
-objClassE{ClassE}

ClassE
-classEID
-status
-objClassA{ClassA}

Here you can see that ClassA is having a relationship with one instance of ClassB , ClassB is having a relationship with one instance of ClassC and so on. Finally ClassE is having an instance of ClassA.
So my question is when I will get an object of ClassA then It will show ClassB instance and inside it ClassB will have ClassC instance, ClassC will show ClassD instance, ClassD will show ClassE and finally ClassE will show ClassA instance again and then same scenario will repeat again, so this way It can show our whole database entry inside a single object of ClassA.

I have just explained this scenario with 5 Classes only, in my case its more than 25 classes which can show this type of scenario between several other classes also.

So, I wanna know-
1 -Is this a good way to create Model class Relationships
2- It seems to have a Recursive behaviour with relationships because we can see every entry of our database in a single instance of any class because, all entries are somehow related to each other.
3- This question arrives when I hold a single instance of Any class in a singleton class then this Instance will basically hold our whole database entries. If I am dealing with an Array of this type objects then each object of the Array will basically hold whole database entries inside a single object. It will create memory issue in our application.

Please give me clarification on this with the solution.

Regards
Naveen Sharma


#2

As we discussed over our support ticket, I would recommend using foreign keys to express your relationships since you are using partial sync which does not have backlinks.