-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
How frequently does the bug occur?
Always
Description
I am experiencing data loss in nested objects when updating an object in Realm JS using the spread operator. Specifically, after the update, one of my nested lists (trackingDataList) gets reset to an empty list.
Realm models
class TrackingData extends Realm.Object { id!: number; progress!: number; static schema: Realm.ObjectSchema = { name: 'TrackingData', primaryKey: 'id', properties: { id: 'int', progress: 'int', }, }; } export default class Profile extends Realm.Object { id!: string; attemptID!: number; lastAccessDate!: Date | null; trackingDataList!: TrackingData[]; sortOrder!: number; from!: Date; userId!: string; static schema: Realm.ObjectSchema = { name: 'Profile', primaryKey: 'id', properties: { id: 'string', attemptID: 'int', lastAccessDate: {type: 'date', optional: true}, trackingDataList: 'TrackingData[]', sortOrder: 'int', from: 'date', userId: 'string', }, }; }
Code Sample
const updatedProfile = { ...currentProfile, lastAccessDate: Moment.utc().format() }; realm().write(() => { realm().create('Profile', updatedProfile, 'modified'); });
Before Update:
{ "id": "12345_2_2", "attemptID": 2, "lastAccessDate": null, "trackingDataList": [ { "id": 1, "progress": 50 } ], "sortOrder": 1, "from": "2024-06-10T10:27:02.909Z", "userId": "12345" }
After Update
{ "id": "12345_2_2", "attemptID": 2, "lastAccessDate": "2024-06-25T16:26:43Z", "trackingDataList": [], "sortOrder": 1, "from": "2024-06-10T10:27:02.909Z", "userId": "12345" }
Stacktrace & log output
Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
N/A
Can you reproduce the bug?
Always
Reproduction Steps
- Create an object in Realm with nested objects/lists.
- Update the object using the spread operator and change a single key.
- Observe that some nested lists are reset or missing after the update.
Version
12.10.0
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
iOS 17.2
Build environment
react-native: 0.74.2
node: v18.17.1
Cocoapods version
1.15.2
- is caused by
-
RCORE-2002 Allow passing a managed collection when setting a Mixed or Collection property
- Closed