0
votes

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 :

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!!

Code with ember 1.5.0 and data-data 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/

I could probably try out "EmbeddedRecordsMixin" but at this point we don't want to change anything in the rest api itself.

Your help will be highly appreciated. Thanks.

1

1 Answers

1
votes

Ember Data wants you to configure the parentQuestion relationship as a 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.