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

JSON.Stringify dont work for realm classes

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None

      Hi, i took a completely new init, and compared a JSON.stringify of a class vs non class.
      It appears that a class dosen't seem to show the properties of the schema. Not sure if its expected.

      You will realize the code is exactly the same as the docs. (using the person class example and the dog json example)
      And you can see the dog works but the person does not

      "react-native": "0.63.2",
      "realm": "^6.0.4"

      class Person {
        get fullName() {
          return this.firstName + ' ' + this.lastName;
        }
      }
      
      Person.schema = {
        name: 'Person',
        properties: {
          firstName: 'string',
          lastName: 'string',
        },
      
      };
      
      const App: () => React$Node = () => {
      
        const [realm, setRealm] = useState(null)
      
        useEffect (()=>{
      
      
          Realm.open({
            schema: [
            {
              name: 'Dog', properties: {name: 'string'}
              }, Person
              ]
              }).then(realm => {
                realm.write(() => {
                  realm.create('Dog', {name: 'Rex'});
      
                  const john = realm.create('Person', {
                    firstName: 'John',
                    lastName: 'Smith',
                    });
                    });
      
                    let dogs = realm.objects('Dog');
                    let persons = realm.objects('Person');
      
                    for (let d of dogs)    console.log("dog ", JSON.stringify(d))  
                    for (let p of persons) console.log("person ", JSON.stringify(p))              
      
                    setRealm({ realm });
                    });
                    }, [])
      

      Linked to https://github.com/realm/realm-js/issues/3117

            Assignee:
            steffen.agger@mongodb.com Steffen Agger (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: