Reputation: 616
I have a new team member, which belongs in a team but the member doesn’t have an ID yet because the record hasn't been send to the server yet how do I tell the team that the member belongs in the team and let it appear in the team list before sending the team member to the server and assigning a unique ID to the member.
Upvotes: 0
Views: 114
Reputation: 564
I think ember is geared towards saving the record to the back end, and then on the success callback creating your relationship and save it again. This ensures that ember-data remains a slave to the backend, ensuring data integrity.
You could look at creating an ID in ember, but this certainly sounds like here be dragons as you would need to purge your ember-data store and and get the real records and ID's from the server.
This process could be simplified by placing a flag on your model to say that it has a generated ID, but as I said here be dragons.
The safest option is to either just establish relationships once a record has been saved to the back end, or if offline is a real concern, you could use something like Ember Pouch to keep a synced local copy of your datastore, this will make the whole issue of resolving ID's a little more consistent.
Finally you could look into some sort of localStorage man in the middle to sync with your db, it has been discussed in this SO question.
Upvotes: 3