# Ember rendering two duplicate records before refresh

**URL:** <https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498>\
**Category:** Uncategorized\
**Created:** [April 20, 2016, 4:43pm UTC](https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498 "2016-04-20T16:43:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helix](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Helix](https://discuss.emberjs.com/u/Helix)\
**Post date:** [April 20, 2016, 4:43pm UTC](https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498/1 "2016-04-20T16:43:02Z")

</div>

I’ve got an unusual problem. On my backend I have an express.js API feeding ember data. Right after I add a new record to the database (I’m running mongo), and then go to the index page which fetches all records I’ll get duplicate records. When I refresh, the duplicate disappears. It only happens some times, and I’m not sure whats casing it. I checked my backend, and it’s only sending any duplicate information.

I’ve attached link to an image that better illustrates the issue.

[http://imgur.com/V4r3jM7](http://imgur.com/V4r3jM7)

---

<div class="post-metadata">

**Author:** ![tomchen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tomchen/32/12234_2.png) [@tomchen](https://discuss.emberjs.com/u/tomchen)\
**Post date:** [April 20, 2016, 11:15pm UTC](https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498/2 "2016-04-20T23:15:47Z")

</div>

It’s hard to say precisely what’s happening without seeing the code. How are you fetching the data in the model hook? What does the save action look like for adding a new record?

---

<div class="post-metadata">

**Author:** ![Helix](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Helix](https://discuss.emberjs.com/u/Helix)\
**Post date:** [April 21, 2016, 4:43pm UTC](https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498/3 "2016-04-21T16:43:05Z")

</div>

The route which creates the record:

```
export default Ember.Route.extend({
  model() {
    return this.store.createRecord('library');
  },

  actions: {
    //where newLibrary is the model we passed in from the template
    saveLibrary(newLibrary) {
      newLibrary.save().then(() => this.transitionTo('libraries.index'));
    },

    willTransition() {
      this.controller.get('model').rollbackAttributes();
    }
  }

});

```

displaying the libraries:

```
export default Ember.Route.extend({
  model() {
    return this.store.findAll('library');
  },
  actions: {
    //where library is the model passed in from the template
    deleteLibrary(library) {
      let confirmation = confirm('Are you sure?');

      if (confirmation) {
        library.destoryRecord();
      }
    }
  }
});

```

the api controller sending the data (I’m transpiling with babel for es6 functionality):

import Library from ‘…/…/models/library’;

```
export default function(req, res) {
  Library.find({}, function(err, libs) {
    if (err) { res.status(400).json(err); }
    res.status(200).json(libs);
  });
}

```

---

<div class="post-metadata">

**Author:** ![Helix](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Helix](https://discuss.emberjs.com/u/Helix)\
**Post date:** [April 21, 2016, 4:45pm UTC](https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498/4 "2016-04-21T16:45:47Z")

</div>

I might of found the problem, I’m using a JSONSerializer, but forgot to change the RESTAPIADAPTER as well.

Ooops.

---

<div class="post-metadata">

**Author:** ![Helix](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Helix](https://discuss.emberjs.com/u/Helix)\
**Post date:** [April 22, 2016, 1:51am UTC](https://discuss.emberjs.com/t/ember-rendering-two-duplicate-records-before-refresh/10498/5 "2016-04-22T01:51:10Z")

</div>

Actually scratch that, seems I’m still getting double records on the initial render.
