I have a model with hierarchical relation like this:
我有一个像这样的层次关系的模型:
App.Question=DS.Model.extend({
name:DS.attr('string'),
childQuestions:DS.hasMany('question',{async:true}),
parentQuestion:DS.attr('string')
});
My payload looks like this :
我的有效负载如下所示:
"questions":[
{
id:1,
name:'question 1',
childQuestions:[]
},
{
id:2,
name:'question 2',
childQuestions:[3]
},
{
id:3,
name:'question 3',
childQuestions:[],
parentQuestion:2
}
]
before with ember 1.5 and ember data beta 3, I was able to do :
在使用ember 1.5和ember数据beta 3之前,我能够做到:
var q = model.findBy('id','2');
console.log(q.get('childQuestions'));//would give me promiseArray with the child questions
but the same returns empty promise array that has nothing even when it resolves!!
但同样返回空的promise数组,即使它结算也没有任何内容!
Code with ember 1.5.0 and data-data 1.0.0 beta 3 : http://emberjs.jsbin.com/zeqomitapi/1/
使用ember 1.5.0和数据数据1.0.0 beta 3的代码:http://emberjs.jsbin.com/zeqomitapi/1/
Code with ember 1.9.1 and data-data 1.0.0 beta 14.1 : http://jsbin.com/koyiqocoyi/1/
代码包含ember 1.9.1和data-data 1.0.0 beta 14.1:http://jsbin.com/koyiqocoyi/1/
I could probably try out "EmbeddedRecordsMixin" but at this point we don't want to change anything in the rest api itself.
我可能会尝试“EmbeddedRecordsMixin”,但此时我们不想改变其余api本身的任何内容。
Your help will be highly appreciated. Thanks.
我们将非常感谢您的帮助。谢谢。
1 个解决方案
#1
1
Ember Data wants you to configure the parentQuestion
relationship as a DS.belongsTo:
Ember Data希望您将parentQuestion关系配置为DS.belongsTo:
App.Question=DS.Model.extend({
name:DS.attr('string'),
childQuestions:DS.hasMany('question',{async:true}),
parentQuestion:DS.belongsTo('question')
});
Updated and working JSBin.
更新并使用JSBin。
#1
1
Ember Data wants you to configure the parentQuestion
relationship as a DS.belongsTo:
Ember Data希望您将parentQuestion关系配置为DS.belongsTo:
App.Question=DS.Model.extend({
name:DS.attr('string'),
childQuestions:DS.hasMany('question',{async:true}),
parentQuestion:DS.belongsTo('question')
});
Updated and working JSBin.
更新并使用JSBin。