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

Realm Result/Object -> String is broken

      <!---

      Questions: If you have questions about HOW TO use Realm, please ask on
      StackOverflow: http://stackoverflow.com/questions/ask?tags=realm
      We monitor the realm tag.

      Feature Request: Just fill in the first two sections below.

      Bugs: To help you as fast as possible with an issue please describe your issue
      and the steps you have taken to reproduce it in as much detail as possible.

      -->

      Goals

      <!--- What are you trying to achieve? -->

      Be able to stringify a realm result for an http api

      Expected Results

      <!--- What did you expect to happen? -->
      A list of objects like defined in the models

      Actual Results

      <!--- What happened instead? -->
      <!--- e.g. the stack trace of a crash -->
      Arrays are Objects
      `
      {
      "0": "Array Item 1",
      "1": "Array Item 2"
      }
      `

      Steps to Reproduce

      <!--- What are steps we can follow to reproduce this issue? -->
      Create any realm model (At least one property List) and stringify the result of any query.

      Code Sample

      <!---
      Please provide a code sample or test case that highlights the issue.
      If relevant, include your model definitions.
      For larger code samples, links to external gists/repositories are preferred.
      Full projects that we can compile and run ourselves are ideal!
      -->

      const Job = {
          name: 'Job',
          primaryKey: 'id',
          properties: {
              id: 'string',
              qualification: {
                  type: 'string?[]',
                  default: []
              }
          }
      };
      // open realm with model and add an example
      
      // example:
      const job = {
          id: "wtf",
          qualification: ["whatever"]
      }
      
      // add to realm
      
      // query
      const results = realm.objects("Job");
      
      console.log(JSON.stringify(results));
      /*
      {
         "0": {
             "id": "wtf",
             "qualification": {
                 "0": "whatever" 
             }
         }
      }
      */
      

      Please, add an option to convert a realm result/object to a plain javascript object or an method to stringify results. Of course there are workarounds, but all of this makes it hard to use realm.

      Version of Realm and Tooling

      • Realm JS SDK Version: 2.17.0

      Btw do not forget #2018 good idea to fix both

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

              Created:
              Updated: