Storing objects in realm store


Can we store objects or nested objects in realm. I have a field which is an object. Is there any way to store that field. eg : obj1 : { type: ‘any string’ } -> Can I store something like this in realm ?


Yes, of course.
Simply use 2 objects :slight_smile:
Like: Obj1 { data: Obj2 }
Obj2 { … }


Does this mean we have to create a separate table and give it’s ref here ??

like my current object (table) has multiple fields…most of which are strings. One of the field is object.

Eg -
Account - table
field list -
name: ‘string’,
age: ‘string’,
address : {
line1 : ‘string’,
line2: ‘string’

so here will address be a different table altogether with 2 fields - line1 & line 2 ?


There are no tables in realm, it is not a relational database.

If you use the same Address model then it will be stored in the same objects (aka. you can access both of them when you write a query on the Address models)

#5[Table_Entry_Id] = ‘string’;[Address] = {type: ‘object’ , objectType:‘string’}

this.realmDbInstance.create(‘XYZ’, realmObj);

Now this is giving me error:
Schema validation failed due to the following errors:

  • Property ‘XYZ.Address’ of type ‘object’ has unknown object type ‘string’


Thats not how you can make parent objects.

You can find a good documentation about the objects here: