Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The current implementation doesn't work with destroyAll() #1

Open
mittinatten opened this issue Nov 2, 2017 · 0 comments
Open

The current implementation doesn't work with destroyAll() #1

mittinatten opened this issue Nov 2, 2017 · 0 comments

Comments

@mittinatten
Copy link

mittinatten commented Nov 2, 2017

Hi,
Thanks for concise and very useful example! I added this functionality to my project very easily based on your description.

I ran into some trouble in my tests where I call PersistedModel.destroyAll() a lot. In that call, ctx.where.id is not defined. Something like this should work for both destroyById() and destroyAll() (adapted from a project where I didn't use promises, and handle errors differently):

Cat.observe('before delete', function(ctx, next) {
  Cat.find(ctx.where, (err, cats) => {
    if (err) return next(err);

    if (cats.length === 0) return next();

    let deletions = cats.map(cat => {
      return {
        'delete': {
          _index: 'cat',
          _type: 'cat',
          _id: cat.id,
        }
      }
    });
    client.bulk({body: deletions}, next);
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant