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

Delete operation hook is not working #14

Open
casamia918 opened this issue May 21, 2017 · 1 comment
Open

Delete operation hook is not working #14

casamia918 opened this issue May 21, 2017 · 1 comment

Comments

@casamia918
Copy link

casamia918 commented May 21, 2017

Hi. Thanks for writing this mixin.

While I use this mixin, I face a situation to use a 'before delete' hook. So I added and tested, but not working.

By reading this mixin's sourcecode, I found that this mixin is overwriting the original loopback PersistedModel's delete methods to its own function. Due to that, it removes the loopback's default operation hook behavior which looks like unintended side effect.

I tried to add remote hook named 'destroyById' method but it also not working.

How do I add 'before delete' hook at current state? My one idea is, create custom delete method and before or after call the destoryById method add my custom behavor like operation hook. Any idea for this?

@jeznag
Copy link

jeznag commented Oct 2, 2019

I did something like this:

Model.destroyById = (id, next) => {
    return softDestroy({ id }, next).then((result) => {
      Model.notifyObserversOf('after delete', {
        instance: {
          id: id
        }
      });
      return result[0];
    });
  };

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

2 participants