Embedded objects in Mongoid change identifiers when upgrading from Ember.js

I have two models in Mongoid: Teams and Players, in which Players are built into Teams.

At the front end, we use Ember.js, and every time I add a new player to the team, I save the parent record (i.e. the team). Each time I update the parent record on the backend in rails, I call:

Team.find(params[:id]).update_attributes(params[:team])

Now the problem is that every time I call update_attributes, all embedded objects (i.e. players) are recreated with new identifiers and saved in the team. This is unexpected since I expect that all old records will continue to be saved with the same identifiers and a new record that will be added to the document.

How to keep the same identifiers for old records?

+3
source share

All Articles