Realm-js: Missing property value for property name

Created on 1 Apr 2016  路  1Comment  路  Source: realm/realm-js

Hi, I'm having problems with optional properties. When I mark property as optional and then I don't set it up on object being saved it throws exception
Unhandled JS Exception: Missing property value for property name

Here is the code I used for saving:

'use strict';

import React, { Component, Text, View } from 'react-native';
import Realm from 'realm';

class Car {}
Car.schema = {
  name: 'Car',
  properties: {
    name: { type: 'string', optional: true },
    make: 'string',
    model: 'string'
  }
}
class TestRealm extends Component {
  render() {
    let realm = new Realm({schema: [Car]});
    let ferrari = new Car();
    ferrari.make = 'Ferrari';
    ferrari.model = 'Enzo';
    realm.write(() => {
      realm.create('Car', {
        make: 'Ferrari',
        model: 'Enzo'
      });
    });
    return (
      <View>
          <Text>Everything went better than expected</Text>
      </View>
    )
  }
}

export default TestRealm;

Most helpful comment

This is a bug. Until we make a fix you have to specify null or undefined for the optional property values at creation time:

realm.create('Car', {
      make: 'Ferrari',
      model: 'Enzo'
      type: null
});

>All comments

This is a bug. Until we make a fix you have to specify null or undefined for the optional property values at creation time:

realm.create('Car', {
      make: 'Ferrari',
      model: 'Enzo'
      type: null
});
Was this page helpful?
0 / 5 - 0 ratings