<!DOCTYPE html>
<html>

  <head>
    <script src="https://cdn.firebase.com/js/client/2.1.2/firebase.js"></script>
    <script src="https://cdn.rawgit.com/js-data/js-data/master/dist/js-data.js"></script>
    <script src="https://cdn.rawgit.com/js-data/js-data-firebase/master/dist/js-data-firebase.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <h1>Open up your console to see the output</h1>
  </body>

</html>
var store = new JSData.DS({
  beforeDestroy: function(resource, attrs, cb) {
    console.log('default beforeDestory');
    cb(null, attrs);
  }
});
var fbAdapter = new DSFirebaseAdapter({
  basePath: 'https://js-data-firebase.firebaseio.com'
});
store.registerAdapter('fb', fbAdapter, {
  default: true
});

var Post = store.defineResource({
  name: 'post',
  beforeDestroy: function(Document, doc, cb) {
    console.log('beforeDestory overridden at resource level');
    console.log('also calling default beforeDestory');
    store.defaults.beforeDestroy(Document, doc, cb);
  }
});
var Page = store.defineResource('page');
var Document = store.defineResource('document');
var doc1, doc2, doc3;

Document.create({
  title: 'foo.txt',
  author: 'John Anderson'
}).then(function(document) {
  doc1 = document;
  return Document.create({
    title: 'bar.txt',
    author: 'John Anderson'
  });
}).then(function(document) {
  doc2 = document;
  return Document.create({
    title: 'baz.txt',
    author: 'Sally'
  });
}).then(function(document) {
  doc3 = document;
  console.log('Document.getAll()', Document.getAll());
  return Document.findAll(null, { bypassCache: true });
}).then(function (documents) {
  console.log('Document.findAll(null, { bypassCache: true })', documents);  

  console.log('Document.destroyAll({ where: { author: { \'==\': \'John Anderson\' } } })');
  console.log('short form: Document.destroyAll({ author: \'John Anderson\' })');
  return Document.destroyAll({
    where: {
      author: {
        '==': 'John Anderson'
      }
    }
  });
}).then(function() {
  console.log('Document.getAll()', Document.getAll());
  return Document.destroyAll();
}).then(function() {
  return Post.destroyAll();
}).then(function() {
  return Page.destroyAll(null, {
    beforeDestroy: function(Page, page, cb) {
      console.log('beforeDestroy overridden during method call');
      cb(null, page);
    }
  });
});
## DS#destroyAll(resourceName[, params][, options])

The "D" in "CRUD". Delegate to the `destroyAll` method of whichever adapter is being used and eject the matching items from the data store.

Returns a promise.

###### Arguments

| name | type | description |
| ---- | ---- | ----------- |
| resourceName | string | The name of the resource to use. Unnecessary if using the resource directly. |
| params | object | Query parameters for selecting which items to destroy. Default: `{}`. |
| options | object | Configuration options. Also passed through to the adapter and (conditionally) to `DS.ejectAll`. |
| options.adapter | string | Override the default adapter. |
| options.beforeDestroy | function | Override the default beforeDestroy hook. |
| options.afterDestroy | function | Override the default afterDestroy hook. |
| options.eagerEject | function | Whether to eject the item from the data store without waiting for a response from the adapter. If an error is thrown the item will be re-injected into the store. Default: `false`. |
| options.notify | function | Whether to call the `beforeDestroy` and `afterDestroy` hooks and emit the `DS.beforeDestroy` and `DS.afterDestroy` events. Default: `true`. |

###### Examples

```js
var params = {
  where: {
    author: {
      '==': 'John Anderson'
    }
  }
};

// See Method Variants section below for different ways to call DS#destroyAll
Document.destroyAll(params).then(function (documents) {
  // The documents are gone from the data store
  Document.filter(params); // []
});
```