2
votes

I am using ember data for my application . I defined two models with belongsTo relationship

App.Queue = DS.Model.extend({
  time_added: DS.attr("string"),
  description: DS.attr("string"),
  video: DS.belongsTo("video")
});

App.Video = DS.Model.extend({
  video_url: DS.attr("string"),
  title: DS.attr('string'),
  duration: DS.attr('number'),
  queue:DS. belongsTo('queue')
});

For adding a video to queue , I do

var queue=this.store.createRecord("queue",{time_added:"2014-04-26",description:"Good to have at this time"});
this.store.find('video',44).then(function(data){
  queue.set('video',data);
  queue.save();
});

response after save will be

{
  queue: {id:1,time_added:"2014-04-26",description:"Good to have at this time",video:44},
  video: [{
    id: 44,
    video_url: "beauty.png",
    title: "Cool dance",
    duration: "30",
    queue: 1
  }]
}

Now it will create new record in the store . But the problem is after save when i check the queue computed property it shows "App.Queue:ember1724:null" [in belongsTo relationship] and when i click on this property it will fetch new record from the server with the same id and remaining values are undefined . I am having doubt that why it should fetch new queue record with same id if it is already there ?

1
having the same problem... i have a hasMany -> belongsTo relationship...jwahdatehagh
Your response from the server is incorrect - video is in an array - but it's a one to one relationship (two belongsTo relationships)jwahdatehagh
Already fixed in ember-data 1.0.0-beta14 github.com/emberjs/data/pull/2576yAnTar

1 Answers

0
votes

This issue has been fixed in ember-data newer versions