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;
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
});
Most helpful comment
This is a bug. Until we make a fix you have to specify
nullorundefinedfor the optional property values at creation time: