Saving an object breaks references

I have a one-to-many relationship defined between User and WorkoutItems. This relationship exists solely for the purpose of saving multiple WorkoutItems at once (by saving the User) in certain situations. However, I’ve noticed a problem when saving a single WorkoutItem at a time.

I have the currently logged in user saved to model singleton. I have a view with a datagrid component that binds its dataprovider to the the WorkoutItems: model.user.workoutItems.

1: A user adds a new WorkoutItem to grid, it’s added via the IList API: grid.dataProvider.addItem(workoutItem)
2: Afterwards, code is executed to save the user along with the its’ newly added WorkoutItem: model.user.save()
3: Everything works perfectly, because the dataProvider is a reference to the model.user.workoutItems.
4: The user repeats step 1 and the User object is saved again. Except the second WorkoutItem is never saved to the backendless database.

The problem is that after the User object is saved the first time, the reference between the grid’s dataProvider and the model is broken. I assume that’s because the User.workoutItems array is rebuilt during the save operation. After that first save, any new WorkoutItems added to the grid do not get added to the model.user.workoutItems array.

After you execute step (2), make sure to rebind your dataProvider to the object returned from the save operation.

Regards,
Mark