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

Realm object constructor must not return another value

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

      I just want to report an issue, please advice me for best practice.

      Code Sample

      I have codes below:

      try {
        const upsert = realm.create('ENTITY_NAME', obj,
      	objects.length > 0 ? UpdateMode.Modified : UpdateMode.Never);
        console.log(`Upserted for entity: ${JSON.stringify(upsert)}`);
      } catch (error) {
        console.error(`Failed to upsert for up entity ${JSON.stringify(obj)}: ${error.message}`);
      }
      

      and

      const Realm = require('realm');
      
      class Entity extends Realm.Object {
      }
      
      Entity.schema = {
        name: ENTITY_NAME,
        primaryKey: 'id',
        properties: {
          id: 'string',
          value: 'string',
          expiredTime: 'date',
          version: { type: 'int', default: 0 },
          schemaVersion: { type: 'int', default: 0 },
        },
      };
      
      export default Entity;
      

      I got error in catch body:

      Realm object constructor must not return another value
      

      But, if change the class entity like:

      class Entity {
      }
      

      NO extends Realm.Object, the error is gone.

      Version of Realm and Tooling

      "realm": "4.0.0-beta.0",
      "react": "16.13.0",
      "react-native": "0.61.5",
      node v10.19.0
      windows 10 64bit
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: