-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
Goals
Being able to create a class model two times
Expected Results
Two models are written to the realm.
Actual Results
The first one is successfully written, the second one throws the following exception:
Steps to Reproduce
Given the following class model (typescript) :
export default class Transaction extends Realm.Object { name: string; date: Date; value: number; _id?: string; constructor(name: string, date: Date, value: number) { super(); this._id = new ObjectId().toHexString(); this.name = name; this.date = date; this.value = value; } static schema: Realm.ObjectSchema = { name: 'Transaction', primaryKey: '_id', properties: { _id: 'string', name: 'string', date: 'date', value: 'int' } }; }
Here's how I setup realm:
const realm = new Realm({schema: [Transaction]});
When I add my first transaction like this:
realm?.write(() => { realm.create( Transaction, new Transaction( "Coffee", new Date(), 35 ) ); });
The first time, everything works as expected, but when I call this code a second time, the app crashes with the exception above.
Ideally I would want to automatically generate an id in my model, so I don't have to duplicate code ( I also need a created_at, updated_at, and I don't want to specify those everytime I create a new object ).
I think the bug is around this line: https://github.com/realm/realm-js/blob/e67a78bb5ad32245a2b531d73ed80baa9570e2a4/src/jsc/jsc_class.hpp#L733
Side note: I wanted to fix the issue myself but wasn't able to compile realm myself. The tests seem to use a private docker repository that I cannot clone
Version of Realm and Tooling
- Realm JS SDK Version: 10.2.0
- Node or React Native: React Native
- Client OS & Version: 0.63
- Which debugger for React Native: None