在修订版12之前,我只需执行以下操作即可创建一个对象,并且它与“hasMany”关系相关联
test("findMany generates http ...", function() {
store.load(Person, {id: 9, name: "Toran Billups", tasks: [1, 2]});
person = store.find(Person, 9);
expectLoaded(person);
equal(ajaxUrl, undefined, "no Ajax calls have been made yet");
var tasks = get(person, 'tasks');
equal(get(tasks, 'length'), 2, ""); //this now fails showing 0 tasks ...
});
但升级后,“任务”似乎是0而不是2,正如我所期望的那样。
以下是模型,如果这有任何帮助
var attr = DS.attr, hasMany = DS.hasMany, belongsTo = DS.belongsTo;
Person = DS.Model.extend({
name: attr('string')
});
Task = DS.Model.extend({
name: attr('string'),
isFinished: attr('boolean'),
owner: belongsTo(Person)
});
Person.reopen({
tasks: hasMany(Task)
});
我知道在加载几个任务后我可以做一个简单的“pushObject”,但我上面测试的目的是验证$ .ajax行为,当我只关联任务ID时,ember-data会获取其余的模型(延迟加载)。是否有可能像我在第12版中所说的那样保留它?
答案 0 :(得分:1)
看起来你需要按照预期在版本12 -works中使用“loadHasMany”选项!
test("findMany generates http ...", function() {
store.load(Person, {id: 9, name: "Toran Billups"});
person = store.find(Person, 9);
store.loadHasMany(person, 'tasks', [ 1, 2 ]);
expectLoaded(person);
equal(ajaxUrl, undefined, "no Ajax calls have been made yet");
var tasks = get(person, 'tasks');
equal(get(tasks, 'length'), 2, ""); //this actually returns 2 :)
});