I have the following Emberjs Data model:
App.File = DS.Model.extend({
like: DS.attr('boolean'),
comments: DS.hasMany('App.Comment')
});
App.Comment = DS.Model.extend({
file: DS.belongsTo('App.File'),
comment: DS.attr('string')
});
And preload it with:
App.store.load(App.File, {id: 1, like: false});
Now I thought, if I get the comments like this:
var f = App.store.find(App.File, 1);
var c = f.get("comments");
var c is a empty EmberArray and a request is send to the server. But I don't get a request? Why and how do I have to do it? I really don't wanna preload the comments.
Further more, if I add a comment, but also change the file simultaneously:
f.get("comments").createRecord({comment: "test"});
f.set("like", true);
App.store.commit();
Two requests are send to the server. But if I then return the following JSON (for the file):
{ "id": 1, like: true }
My first visible comment disappears again. Why? And what do I have to do?
Thanks for your help!