Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember Data BelongTo Relationship :Duplicate record after save #1893

Closed
maheshiv opened this issue Apr 25, 2014 · 3 comments
Closed

Ember Data BelongTo Relationship :Duplicate record after save #1893

maheshiv opened this issue Apr 25, 2014 · 3 comments

Comments

@maheshiv
Copy link

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 ?

I think you understand my problem . Thanks in advance .

@maheshiv maheshiv changed the title Ember Data BelongTo Relationship : Error in fetching record after save Ember Data BelongTo Relationship :Duplicate record after save Apr 29, 2014
@sandstrom
Copy link
Contributor

Minor note: I think these cases may be related: #1829, #1656

@darkbaby123
Copy link

@igorT @stefanpenner Any new information on this issue? I met the same problem on saving a new embedded "belongsTo" record.

I understand that when sending a non-id embedded record to server and server returns the same record with id, Ember Data will think that server's response is a new record, but not updating the old non-id record. But I'm curious same situation happens when creating a new record (non-embedded) using a POST request, and Ember Data knows that the server response is for that new record. I'm looking at the source to see how Ember Data do it. Maybe it helps.

@igorT
Copy link
Member

igorT commented Dec 22, 2014

This should've been fixed on master. Please reopen if still an issue.

@igorT igorT closed this as completed Dec 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants