# destroyRecord is not a function

**URL:** <https://discuss.emberjs.com/t/destroyrecord-is-not-a-function/10246>\
**Category:** Ember Data\
**Created:** [March 22, 2016, 4:59pm UTC](https://discuss.emberjs.com/t/destroyrecord-is-not-a-function/10246 "2016-03-22T16:59:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayoros\_42](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Ayoros\_42](https://discuss.emberjs.com/u/Ayoros_42)\
**Post date:** [March 22, 2016, 4:59pm UTC](https://discuss.emberjs.com/t/destroyrecord-is-not-a-function/10246/1 "2016-03-22T16:59:16Z")

</div>

Hello,

I have two models:

campaign:

```
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  address: DS.belongsTo('address')
});

```

address:

```
import DS from 'ember-data';

export default DS.Model.extend({
  campaign: DS.belongsTo('campaign'),
  name: DS.attr('string'),
  lat: DS.attr('number'),
  lon: DS.attr('number')
});

```

A route campaign\_new:

```
export default Ember.Route.extend({
  model() {
    let campaign = this.store.createRecord('campaign');
    this.store.createRecord('address', {
      campaign: campaign
    });
    return campaign;
  },
  exit() {
    let campaign = this.currentModel;
    let address = campaign.get('address');
    if (address.get('id') == null)
      address.destroyRecord();
    if (campaign.get('id') == null)
      campaign.destroyRecord();
  }
});

```

But on exit, this error occured:

`Error while processing route: app.campaigns address.destroyRecord is not a function TypeError: address.destroyRecord is not a function`

I have a similar error on address.save().

(My models and routes are simplified for more readibility).

Anyone has an idea ? 🙂

---

<div class="post-metadata">

**Author:** ![nerdyworm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nerdyworm/32/3860_2.png) [@nerdyworm](https://discuss.emberjs.com/u/nerdyworm)\
**Post date:** [March 22, 2016, 10:38pm UTC](https://discuss.emberjs.com/t/destroyrecord-is-not-a-function/10246/2 "2016-03-22T22:38:22Z")

</div>

It could be that the address relationship is async by default.

So:

```auto
campaign.get('address').then(function(a) {
  if (a.get('id') === null) {
    a.destroyRecord();
  }
});

```

You could set the relationship to ` {async: false}`.

Let me know if this helps!

Ben

---

<div class="post-metadata">

**Author:** ![Ayoros\_42](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@Ayoros\_42](https://discuss.emberjs.com/u/Ayoros_42)\
**Post date:** [March 23, 2016, 9:12am UTC](https://discuss.emberjs.com/t/destroyrecord-is-not-a-function/10246/3 "2016-03-23T09:12:37Z")

</div>

Effectively, i forgot to use the callback notation ( I come from ruby 😄 ) , it works fine.

Thanks a lot !
