Reputation: 4484
I have a strange problem. I've written a REST api in node to handle requests from Ember.
Data can be retrieved with GET and saved with POST. But when a new record is created and I redirect to a page displaying the the newly saved record its ID in the path is shown as "null". If I go back to the page displaying the entire collection, the new record is displayed in duplicate; One with the proper ID in its path and one with "null". If I reset the page the null entry disappears.
I guess what's going on is that there is temporarily an ember object in memory that is not receiving the ID even though the record is saving correctly to the database and persisting.
I have a feeling this has something to do with mongo's _id
versus what Ember usually expects (id
) which I have tried to fix overriding the RESTSerializer's primaryKey property.
Upvotes: 1
Views: 87
Reputation: 4484
After hours of searching I found my problem.
In my node server...
newFriend.save(function(err,friend){
if (err) throw err;
res.writeHead(201, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({"friend": newFriend.toObject()}));
res.end();
});
Server must respond with 201 and the saved object wrapped in an object with the model name as it's key.
Upvotes: 2