-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail to create / push an object with linkingObjects to its parent #1475
Comments
And you don't observe it when you remove |
I rewrite the code in the following way, by separating the creation of Car and Person. And then link them together. It does not freeze after trigger the linkage, but neither Car and Person object shows their linkage after refresh. Once I click "Link Car to Person", a yellow warning message is prompted. "Possible Unhandled Promise Rejection (id: 1): Error: properties must be of type 'object', got (undefined)" ==> Why so? Please help
|
|
Thanks, it should be realm.create('Person')[0]. But when I tried with the amended code, the objects cannot yet linked together. |
By the way, I tried below using the version 1.13.0 and 2.0.5 respectively.
|
When you have a few minutes, it would be great if you tried to rewrite |
@kneth Did the schema format change from 2.0.x? Are changes documented somewhere? Are you saying this is no longer valid schema ?
|
@esutton The old one should work but |
I love the shorthand and also the array of primitive type a lot. But as I cannot use 2.0.x, I cannot enjoy the new features. |
@adrianchancy Please take a look at https://github.com/realm/realm-js/blob/master/tests/js/linkingobjects-tests.js and see if you are using Realm in a different way. If you are, I will be happy if you can contribute a test to expose any bugs. |
I have the same problem. I think it might have to do with the .push method ... App screen freezes after push execution of linked object. My schema: class Log extends Realm.Object {}
Log.schema = {
name: 'Log',
properties: {
date: 'date',
elapsedSeconds: 'int',
belongsTo: {type: 'linkingObjects', objectType: 'Activity', property: 'logs'}
}
};
class Activity extends Realm.Object {}
Activity.schema = {
name: 'Activity',
primaryKey: 'id',
properties: {
id: {type: 'int', indexed: true},
label: 'string',
color: 'Color',
logs: 'Log[]',
}
}; Creation of a log object in the realm (works), fetching an activity from the realm(works): realm.write(() => {
let newLog = realm.create('Log', {date: new Date(), elapsedSeconds: elapsedSeconds});
let editActivity = realm.objectForPrimaryKey('Activity', currentActivity.id);
editActivity.logs.push(newLog); // <- this breaks it
}); If i rewrite the Question on the side .. is there a special reason, why lists are objects of objects |
@JohnBra In #2370 I have added a test which is inspired by your code snippet. On node.js it does not fail.
The reason is that the objects are not plain JS objects but "managed" objects. That is, a collection is not an array but an object which has most of the behaviour of an array. |
@kneth thank you for the quick reply! I have just tested it on a clean react-native app with not additional libs and code ... sadly it shows the same behaviour. Tested on device (Android 6) and emulator (iOS, iPhone X 12.2). Steps to reproduce
This is the code i used: import React, {Component} from 'react';
import {StyleSheet, Text, View, TouchableHighlight} from 'react-native';
const Realm = require('realm');
const ColorSchema = {
name: 'Color',
primaryKey: 'id',
properties: {
id: {type: 'int', indexed: true},
value: 'string'
}
};
const LogSchema = {
name: 'Log',
properties: {
date: 'date',
elapsedSeconds: 'int',
belongsTo: {type: 'linkingObjects', objectType: 'Activity', property: 'logs'}
}
};
const ActivitySchema = {
name: 'Activity',
primaryKey: 'id',
properties: {
id: {type: 'int', indexed: true},
label: 'string',
color: 'Color',
logs: 'Log[]'
}
};
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = { realm: null };
}
addItemsToRealm() {
Realm.clearTestState();
Realm.open({
schema: [ActivitySchema, LogSchema, ColorSchema]
}).then(realm => {
realm.write(() => {
let color = realm.create('Color', {id: 1, value: '#f00'});
let activity = realm.create('Activity', {id: 1, label: 'Tmp Activity', color: color, logs:[]});
// create log separately and then push
//let log = realm.create('Log', {date: new Date(), elapsedSeconds: 42});
//activity.logs.push(log);
// create log in push command (best for my usecase)
activity.logs.push({date: new Date(), elapsedSeconds: 42});
// create activity after log including log in array (doesn't fit my usecase) also breaks
//let activity = realm.create('Activity', {id: 1, label: 'Tmp Activity', color: color, logs:[log]});
let getAllActivities = realm.objects('Activity');
console.warn(getAllActivities);
});
this.setState({ realm });
});
}
render() {
const info = this.state.realm
? 'Number of Activities in this Realm: ' + this.state.realm.objects('Activity').length
: 'Loading...';
return (
<View style={styles.container}>
<TouchableHighlight onPress={() => this.addItemsToRealm()}>
<Text>Click to add items to Realm</Text>
</TouchableHighlight>
<Text style={styles.welcome}>
{info}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
}); I have included a few different ways to add a log to the activity object (see commented lines). None of those work. |
I'd be happy to lend a you a hand testing on react-native @kneth |
I guess that is something related to the object we got. |
@adrianchancy thanks for the help! It seems to be this exact problem ... in my applications it still breaks for both cases (remote debugging on and off) |
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
Code Sample
I modified a bit of your example to simulate my case and I got the same result.
Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: