Accessing specific data selected by schema


([email protected]) #1

Hi everyone,

I have just a simple question. When I open realm with only specific schema, how can I access to all its members. Example:
I created specific schema (schema A) with specific properties, but these objects are just properties of bigger schema (schema B).
If I open Realm with only schema A, is it possible to get all objects of this schema?

Thank you very much for your suggestions.


(Zsolt Jandzso) #2

A realm has one schema, if its different than the actual schema then you need to do migration between the versions (or you can completely remove the old one with all of the existing data)


([email protected]) #3

I suppose we are talking about two different things.
In Realm according to documentation it is possible to create Schema (or Model):

Person.schema = {
  name: 'Person',
  properties: {
    firstName: 'string',
    lastName: 'string'
  }
};

Let’s imagine, that in properties of Person I’m using another Schema as a property like this:

Person.schema = {
  name: 'Person',
  properties: {
    address: 'string',
    name: 'Name'
  }
};
Name.schema = {
  name: 'Name',
  properties: {
    first: 'string',
    second: 'string'
  }
}

My question is if I can access to Name(s) only by opening Realm like this:

Realm.open({schema: [Person]})
  .then( /* here I want Name(s) only */ );

(Zsolt Jandzso) #4

No, we are talking about the same things.

In this scenario, you have 2 different schema for the Person model. Thats not allowed.
However you can make a Person with firstName, lastName, address and name property, and use that model.