Fail to create / push an object with linkingObjects to its parent
See original GitHub issueQuestions: In another project, I can use linkingObjects well. But I don’t know why I cannot create or push object with linkingObjects to its parent for now. Once I create or push object linkingObjects to its parent, the UI freezes and the app cannot run. I force quit the app and reenter it. The UI still freezes and the app cannot run.
Please help.
Expected Results
It can update / create the object
Actual Results
It cannot update / create the object. The UI freezes even after force quit and reopen the app. And the app cannot run.
Steps to Reproduce
- Run the below code
- tap “Click me.”
Code Sample
I modified a bit of your example to simulate my case and I got the same result.
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
const Realm = require('realm');
const CarSchema = {
name: 'Car',
properties: {
make: 'string',
model: 'string',
miles: { type: 'int', default: 0 },
owners: { type: 'linkingObjects', objectType: 'Person', property: 'cars' } // What I added
}
};
const PersonSchema = {
name: 'Person',
properties: {
name: 'string',
birthday: 'date',
cars: 'Car[]',
picture: 'data?'
}
};
export default class App extends Component {
Update = () => {
Realm.open({ schema: [CarSchema, PersonSchema] })
.then(realm => {
realm.write(() => {
const myCar = realm.create('Car', {
make: 'Honda',
model: 'Civic',
miles: 1000,
});
myCar.miles += 20;
});
const cars = realm.objects('Car').filtered('miles > 1000');
realm.write(() => {
const myCar = realm.create('Person', {
name: 'Adrian',
birthday: new Date(),
cars: [{
make: 'BMW',
model: '8310',
miles: 200
}]
});
});
alert(JSON.stringify(realm.objects('Car')))
});
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', }}>
<Text onPress={() => this.Update()} style={{ alignSelf: 'center' }}>
Click me.
</Text>
</View>
);
}
}
Version of Realm and Tooling
- Realm JS SDK Version: 2.0.3
- React Native: 0.50.1
- Client OS & Version: Android 7.0, iOS 11 (Both simulator and real device)
- Which debugger for React Native: Google Chrome (It happens even without debugger)
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Realm LinkingObjects second level returning nil
This code solves the problem for the first parent. But for the grand parents(!) this return nil again. So this is not the...
Read more >Blender 2.7 Tutorial #15 : Linking Objects (Parent/Child)
In this Tutorial #15 I cover: -Linking one object to another by creating a ' parent /child' link. - Creating hierarchies of linked...
Read more >Creating Movements — OpenToonz 1.6.0 documentation
Links can be selected together with objects (see Linking Objects ). Tip. To move the selection ... To set the way a child...
Read more >Linking Objects with the Grid DTC
This month, I'll show you how to extend that functionality by linking a Grid DTC to another data-bound object to display parent/child relationships....
Read more >Realm: Create reactive mobile apps in a fraction of the time
Create a test database with sample data using the menu item Tools ... the file protection attributes to the parent folder containing these...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’d be happy to lend a you a hand testing on react-native @kneth
@esutton The old one should work but
cars: Car[]is the new one way. From 2.0.0, you can also havenames: string[]so you don’t have to create a wrapper for primitive types like numbers and strings 😄.