Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-197

Realm schema contains linkingObjects

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      Similarly to default values,linkingObjects are not stored inside the Realm, so when I call Realm.schema this property should not show up.

      Currently, the behaviour depends on whether you open the Realm using its path only, or using path + schema.

      When opening the Realm using its path, the linkingObjects property is not returned, this is the correct behaviour (as it's not stored in the Realm). However, when you use the schema the property is returned, which is inconsistent and incorrect.

      This issue is preventing Realm Studio https://github.com/realm/realm-studio/pull/428 to export a correct model.

      I've created a test to demonstrate this behaviour

      var Realm = require('realm');
      var model = require('./SampleTypes');
      
      const openRealmUsingSchema = function (path, schema) {
          return new Realm({
            path,
            schema
          });
        };
      
      const openRealmUsingPath = function (path) {
      return new Realm({
          path
      });
      };
      
      
      console.log(">>>>>>>>>>>>>>> Create then open a Realm using schema <<<<<<<<<<<<<<<");
      console.log("!!! notice that 'objectsLinkingToThisObject' part of the schema (incorrect behaviour)\n");
      let mySchemaRealm = openRealmUsingSchema("realms/SampleTypes.realm", [
          model.SampleTypes,
        ]);
      console.log(mySchemaRealm.schema[0].properties);  
      mySchemaRealm.close();
      
      
      console.log(">>>>>>>>>>>>>>> Open the Realm again using the path only <<<<<<<<<<<<<<<");
      console.log("!!! notice that 'objectsLinkingToThisObject' IS NOT part of the schema (correct behaviour)\n");
      let myPathRealm = openRealmUsingPath("realms/SampleTypes.realm");
      console.log(myPathRealm.schema[0].properties);  
      myPathRealm.close();
      
      exports.SampleTypes = {
          name: 'SampleTypes',
          primaryKey: 'primary',
          properties: {
              primary: 'int',
              ArrayFloatValue: 'float?',
              listOfStrings: 'string[]',
              listOfOptionalDates: 'date?[]',
              indexedInt: {type: 'int', indexed: true},
              linkToObject: 'SampleTypes',
              listOfObjects: 'SampleTypes[]',
              objectsLinkingToThisObject: {type: 'linkingObjects', objectType: 'SampleTypes', property: 'linkToObject'}
          }
      }
      

      I've uploaded the project as well here

            Assignee:
            Unassigned Unassigned
            Reporter:
            nabil.hachicha@mongodb.com Nabil Hachicha
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: