# Remove id of deleted record on many to many relationship

**URL:** <https://discuss.emberjs.com/t/remove-id-of-deleted-record-on-many-to-many-relationship/8121>\
**Category:** Ember Data\
**Created:** [June 2, 2015, 4:31pm UTC](https://discuss.emberjs.com/t/remove-id-of-deleted-record-on-many-to-many-relationship/8121 "2015-06-02T16:31:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo\_Merino](https://avatars.discourse-cdn.com/v4/letter/p/b5e925/32.png) [@Pablo\_Merino](https://discuss.emberjs.com/u/Pablo_Merino)\
**Post date:** [June 2, 2015, 4:31pm UTC](https://discuss.emberjs.com/t/remove-id-of-deleted-record-on-many-to-many-relationship/8121/1 "2015-06-02T16:31:32Z")

</div>

Hello! I’m having a small problem. I have two models: Story and Category, which are related many to many:

```
// app/models/story.js
export default DS.Model.extend({
  title: DS.attr('string'),
  text_content: DS.attr('string'),
  excerpt: DS.attr('string'),
  creation_date: DS.attr('date'),
  external_id: DS.attr('string'),
  categories: DS.hasMany('category', { async: true }),
})

// app/models/category.js
export default DS.Model.extend({
  name: DS.attr('string'),
  iptc: DS.attr('string'),
  stories: DS.hasMany('story', { async: true }),
  original_name: DS.attr('string')
})

```

Now I’m trying to delete them in this function:

```
deleteCategory: function(category) {
  category.deleteRecord();
  category.save();
}

```

However, this deletes the category but the stories that had its ID assigned still have it, but since we deleted it, Ember Data can’t find it, resulting in `TypeError: Cannot read property 'stories' of undefined`. What’s the most appropriate way to delete a many-to-many record and update the related records accordingly? Thanks!
