In older versions of Ember and Ember Data a model ID could be a string, when passed from the server. With some changes I’m making to my app now, it seems as if that’s no longer the case?
The Set Up
Ember: 1.3.0-beta.1+canary.ea261c9f
Ember Data: 1.0.0-beta.2
Handlebars: 1.0.0
jQuery: 2.0.3
When my route loads, I’m grabbing an account from the server:
/api/1/accounts/10001262/
{
username: "HallOatesFan",
interactions: [
"e0ac813142e56cf35c587232438e0677",
"twitter-tweet-403630764916363265-10001262",
],
messages: [
2057,
2056
]
}
Social.Account = DS.Model.extend({
username: DS.attr("string"),
messages: DS.hasMany("message"),
interactions: DS.hasMany("interaction"),
});
Social.Message = DS.Model.extend({
text: DS.attr("string"),
account: DS.belongsTo("account"),
});
Social.Interaction = DS.Model.extend({
native_id: DS.attr("string"),
account: DS.belongsTo("account"),
});
The Problem
If the interactions array on the account model is empty, Ember fires a request to get messages, then loads them into the page.
/api/1/accounts/10001262/messages/
// returns an array of objects
However, when I try to do the VERY same thing for interactions, I get an error:
Assertion failed: You must include an `id` in a hash passed to `push`
Assertion failed: Cannot call get with 'isEmpty' on an undefined object.
And Ember never even tries to load the interactions endpoint.
From past experience I know this is because Ember doesn’t have an ID to associate with the record. If I return a dummy number in the interactions array from the accounts endpoint, Ember remains happy.
Is this a change that has been made to Ember Data? I’m almost positive that Ember previously allowed string IDs. I’d really love some guidance.