question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fail to create / push an object with linkingObjects to its parent

See original GitHub issue

Questions: 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

  1. Run the below code
  2. 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:closed
  • Created 6 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JohnBracommented, May 14, 2019

I’d be happy to lend a you a hand testing on react-native @kneth

1reaction
knethcommented, Nov 10, 2017

@esutton The old one should work but cars: Car[] is the new one way. From 2.0.0, you can also have names: string[] so you don’t have to create a wrapper for primitive types like numbers and strings 😄.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found