Duplicate data on navigation without page reload using ember-data
I am using ember.js 1.0.0-pre4, ember-data revision 11.
I have the following model:
App.DbProcess = DS.Model.extend({
pid: DS.attr('number'),
backendStart: DS.attr('string'),
transactionStart: DS.attr('string'),
queryStart: DS.attr('string'),
stateChange: DS.attr('string'),
waiting: DS.attr('boolean'),
state: DS.attr('string'),
query: DS.attr('string')
})
By following route:
App.HomeDbProcessesRoute = Ember.Route.extend({
model: function() {
return App.DbProcess.find();
}
})
Then I have a template that it uses {{#each controller}}{{/each}}
to render all of the extracted processes. However, if I navigate to other pages (without reloading the page) and return back to the processes page, the processes are restored again and the duplicates are displayed on the page.
EDIT : I also tried this, but it didn't work:
DS.RESTAdapter.map('App.DbProcess', {
primaryKey: 'pid'
})
I had the same problem now and here is my little hot problem:
{{#if id}}
<div>
{{title}}
</div>
{{/if}}
In the template, I only process an item from the store if it has an ID (only those coming from the database). But you may have solved that already!
(using revision 12)
It turns out you can do something like this to set up the primary key globally
App.Adapter = DS.RESTAdapter.extend({
url: document.location.protocol+'//url-api.com',
serializer: DS.RESTSerializer.extend({
primaryKey: function(type) {
// If the type is `BlogPost`, this will return
// `blog_post_id`.
var typeString = (''+type).split(".")[1].underscore();
return typeString + "_id";
}
})
})